Search code examples
applescript

Why doesn't my AppleScript quit when I click Cancel in a dialog?


I have this line in an AppleScript

set theResponse to display dialog "Name?" default answer myname with icon note buttons {"Cancel", "Continue"} default button "Continue"

If I click cancel the script continues. I want it to quit.

However, if I click cancel in this dialog:

display dialog "cancel"

the execution is interrupted.

  • Both lines are at the "root" level, that is, no try, if or similar clause.
  • I am not using English as my system language.
  • I have read this question How to tell an Applescript to stop executing but the solutions there didn't seem applicable for my situation.

Solution

  • The Cancel button is localized. It works if you use the name in your system language.

    You can specify an explicit cancel button in display dialog which works in any localization

    set theResponse to display dialog "Name?" default answer myname with icon note buttons {"Quit", "Continue"} cancel button "Quit" default button "Continue"
    

    If you click Quit the button behaves like the standard Cancel button. It throws error -128 which is User cancelled