Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading