To witness the issue to which I refer, follow these steps:
-
Create an AppleScript that simply contains one
display dialog
dialog. -
Save this script as an .app file.
-
Run the .app file.
If you right-click the file's Dock icon, then left-click Quit, as depicted in the following screenshot:
you will observe that nothing happens. That is, the application remains open.
The keyboard shortcut, ⌘ command + Q, is similarly futile.
The only way to quit this application (excluding clicking "Force Quit" in Activity Monitor.app) is to click a button in the application's active dialog.
Is it possible to make an AppleScript application's inherent "Quit" function quit out of the application, even if the application is currently displaying a dialog when the "Quit" function is called?
Note: The display alert
dialog and the choose from list
dialog behave in the same domineering manner as the display dialog
dialog.
Best Answer
The short answer is, no.
The longer answer is: By design, an AppleScript's
display dialog
creates an application modal object, meaning that until the User responds to the controls of the object, the application waits until is receives appropriate input to that object in order for it to continue.If a Cancel button exists and not the default button, it can be dismissed by pressing the Esc key or a Command-period key press to activate the Cancel button. If you use a Cancel button, you can trap the error and execute a
return
that will halt execution of the remaining code of the app.If if doesn't have a Cancel button then it can't be dismissed without direct interaction or forced quit by any one of several methods.
To force quit:
Also, ⌘Q doesn't work because it's grayed out in the App's Menu bar menu.
All this is also true within the Script Editor itself, not just with an AppleScript app. Once a
display dialog
is present it must be interacted with appropriately or the app forced quit by one method or another.