2

To witness the issue to which I refer, follow these steps:

  1. Create an AppleScript that simply contains one display dialog dialog.

  2. Save this script as an .app file.

  3. 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.

3
  • 1
    ⌘Q doesn't work because it's grayed out in the App's Menu bar menu. You can option-right-click the app's Dock tile and select Force Quit from App's Dock tile context-menu. That said, I do not believe there is any standard AppleScript code you can implement that will quit the app while the display dialog is present by clicking Quit on the App's Dock tile context-menu. Commented Jun 11, 2017 at 4:20
  • 1
    I was unfamiliar with option-right-click, "Force Quit." That's a nice tip. This method indeed closes the dialog and the application, just as I desire. I can't imagine that there exists a better answer. So, if you want to post that as an answer, I'll accept it. Thanks! Commented Jun 11, 2017 at 4:42
  • I was to tired last night to write it in the form of a proper answer. :) Commented Jun 11, 2017 at 19:54

1 Answer 1

2

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:

  • You can option-right-click the app's Dock tile and select Force Quit from App's Dock tile context-menu.
  • Press Option-Command-Esc to bring up the Force Quit Applications dialog box.
  • Force quit it from Activity Monitor.
  • Its process can also be killed from Terminal in a few different ways, but beyond the scope of this answer as it's not a GUI method.

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .