Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

"display alert" problems with Automator

I want to use the display alert command in my Automator application but the following won't compile:


display alert "foobar" buttons {"Cancel", "OK"}


and this error message pops up:


Syntax Error

Expected end of line, etc. but found plural class name.


and it selects the word "buttons".


The same line of code works in AppleScript Editor. It just doesn't make sense to me.


If I take away the "buttons" part it also works in Automator but why should I be unable to add buttons? (By the way, "cancel button "whatever"" won't compile in Automator either and raises the same error).


Finally, the only reason I am resorting to "display alert" at all instead of using "display dialog" (which doesn't have said issue in Automator) is that "display dialog" doesn't increase the popup's height to accomodate multiple lines of text. Both of these commands are just a pain in the neck.


Thanks in advance for any clues of solving this.

MacBook Pro, Mac OS X (10.6.8), Late 2011, 17-inch

Posted on Jan 9, 2013 1:04 PM

Reply
Question marked as Best reply

Posted on Jan 9, 2013 1:48 PM

Unfortunately, several commands are different in Automator, and override the regular behavior - from its scripting dictionary, the parameters for Automator's display alert are:

  • reference -- the object for the command
  • [afterwards calling data] -- the script to run when the alert is finished
  • [alternate button Unicode text] -- the title of the alternate button
  • [as critical / informational / warning] -- the type of alert (default is informational)
  • [attached to window] -- the window to attach the alert to
  • [default button Unicode text] -- the title of the default button
  • [message Unicode text] -- the message for the alert
  • [other button Unicode text] -- the title of the other button


Alternatively, you can tell another application (something like System Events, which is faceless) to display the dialog, which results in the normal flavor.

5 replies
Question marked as Best reply

Jan 9, 2013 1:48 PM in response to temhawk

Unfortunately, several commands are different in Automator, and override the regular behavior - from its scripting dictionary, the parameters for Automator's display alert are:

  • reference -- the object for the command
  • [afterwards calling data] -- the script to run when the alert is finished
  • [alternate button Unicode text] -- the title of the alternate button
  • [as critical / informational / warning] -- the type of alert (default is informational)
  • [attached to window] -- the window to attach the alert to
  • [default button Unicode text] -- the title of the default button
  • [message Unicode text] -- the message for the alert
  • [other button Unicode text] -- the title of the other button


Alternatively, you can tell another application (something like System Events, which is faceless) to display the dialog, which results in the normal flavor.

Dec 16, 2014 4:17 AM in response to temhawk

Hi temhawk, I'm really new to scripting, I've exactly the same problem you had with "display alert" in Automator.

I can't understand how to deal with the indication provided by red_menace, can you please tell me how should your original sentence (display alert "foobar" buttons {"Cancel", "OK"}) be written in a Run Applescript action? Or maybe is it not possible to use the "display alert" statement within automator?


I really appreciate any help you can provide.

Thanks,

Alessandro

Dec 16, 2014 4:48 AM in response to AlexCoco_

I can't find the Automator workflow I was working on anymore and I've since upgraded to OS X Mavericks and it looks like things have changed - Automator does not give me that error anymore when I try to run that same piece of code.


However, if you're on an older version of OS X, try the following:


tell application "System Events"
  display alert "foobar" buttons {"Cancel", "OK"}
end tell


Screenshot below:

User uploaded file

"display alert" problems with Automator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.