How to make a Command + Q confirmation box in three super easy steps

It's been a while since I posted something on this forum, I've been doing iOS jailbreak/customisation stuff.
But I'm back and I'm posting a tutorial on how to make a Command + Q confirmation box to prevent accidentally quitting an app.


Step one:

Open BetterTouchTool, and go to Command + 4 (keyboard shortcuts). Make a new shortcut that does Command + Q.

Step two:
Set the action to 'Run Apple Script (blocking)', and paste in this script:

tell application "System Events" to set FrontmostApp to name of application processes whose frontmost is true

display alert "⌘Q

Are you sure that you want to quit " & FrontmostApp & "?" message "______________________

Any unsaved changes will be lost." as critical buttons {"Quit all Apps", "Yes", "No"} default button 2 cancel button "No"

if the button returned of the result is "yes" then

tell application (path to frontmost application as text) to quit

else if the button returned of the result is "Quit all Apps" then

-- get list of open apps

tell application "System Events" to set theapps to name of every application process whose visible is true and name is not "Finder"

set keepapp to {"Finder", "BetterTouchTool"}

-- quit each app

repeat with closeapp in theapps

if closeapp is not in keepapp then quit application closeapp

end repeat

end if

Step three:
Now, close the BTT window, and you'll get this pop-up when you press Command + Q:


Extra for experts

When you press 'Quit all Apps', you'll quit everything except Finder and BetterTouchTool. To customise what quits and what doesn't quit, find the line in the code that says set keepapp to {"Finder", "BetterTouchTool"}, and put the exact name of the apps you want kept open. To find the exact name, open the app and look at the left of the menu bar on your screen. It will say the name of the app.

When you add your own apps to the list of apps you want kept open, make sure they are inside speech marks (") and are separated by a comma (,). The last one on the list does not have to have a comma at the end, just leave it.


I hope this helps some people!

1 Like

very nice. Thanks

1 Like

First, thank you for sharing! These kind of script that save us from buying "expensive" app to prevent accidental quit is always appreciated.

However, I've not tried the script and want to ask whether if you press ⌘Q twice, will you trigger the "Quit all Apps"? Given macOS' behavior on popup, ⌘ combined with character will trigger the button that started with that character

I never thought of that, maybe you can add that yourself in the Key Sequences section.

1 Like

Tried this on macOS 14.5, but it stopped ⌘Q from working on all other apps.

So I updated it with a simpler modal. You can modify the list of apps this affects, look in the code where I added BoltAI as an example.

tell application "System Events" to set FrontmostApp to name of first application process whose frontmost is true

if FrontmostApp is in {"BetterTouchTool", "BoltAI"} then
    display alert "Are you sure you want to quit " & FrontmostApp & "?" message "" as critical buttons {"Yes", "No"} default button 2 cancel button "No"
    
    if the button returned of the result is "Yes" then
        tell application FrontmostApp to quit
    end if
else
    -- Pass through Command+Q to other applications
    tell application "System Events" to keystroke "q" using {command down}
end if