Search code examples
macosapplescriptmacos-sierra

AppleScript "with icon stop" for display dialog not working on MacOS 10.12


On MacOS 10.5, this osascript command works as expected, displaying a dialog box with a red stop sign:

osascript -e 'tell app "System Events" to activate' 
          -e 'tell app "System Events" to display dialog "Picking a folder failed, exiting." with title "Start Up Error" buttons "Ok" with icon stop default button "Ok"' 
          -e 'tell app "System Events" to quit'

One MacOS 10.12, however, this command fails with the following cryptic error message:

427:433: syntax error: Expected end of line, etc. but found class name. (-2741)

I've found that changing the icon "stop" above to "note" works on 10.12, displaying a dialog box without error, for example:

osascript -e 'tell app "System Events" to activate' 
          -e 'tell app "System Events" to display dialog "Picking a folder failed, exiting." with title "Start Up Error" buttons "Ok" with icon note default button "Ok"' 
          -e 'tell app "System Events" to quit'

Can anyone else reproduce this issue? Is there a way to fix it other than avoiding the stop icon? I'm guessing it's a bug in AppleScript, but perhaps I'm missing something.


Solution

  • In general, if you wish to target any AppleScriptable app which exhibits such a terminology conflict, it's also usually possible to first assign the conflicting term to a variable in an outer scope, and then within the tell scope use that variable instead.

    For instance, in the case of the System Events app's conflict with the stop term (from StandardAdditions.osax), you could do the following:

    osascript -e 'set kStopIcon to stop' \
              -e 'tell application "System Events" to display dialog "Picking a folder failed, exiting." with title "Start Up Error" buttons {"Ok"} with icon kStopIcon default button "Ok"'
    

    {A few other more-or-less pedantic adjustments have also been made: there's now an explicit line continuation (\newline), for ease of testing in a shell; and, the buttons … labeled parameter now directly specifies a list, instead of involving an implicit coercion.}