HOW TO: Prevent Mac apps to quit on you
Have you ever accidentally typed Command+Q (which is the standard Quit command on Mac OS X) instead of Command+W (standard for closing a window or a tab)?
I know I did… one time too many after which I googled for like 2 minutes and found how to fix this. Another 10 minutes later, here’s a digest with two concrete examples for all of you to peruse.
Mac software can store various settings in the so called Mac OS X user defaults system. Windows users may liken this to Windows Registry. It’s quite similar but somewhat easier to use. For example, you can access the defaults system from the command line using the full glory of command line tools which is exactly what I’m using here.
- Choose the application which quit shortcut you want to reconfigure (e.g. Chrome) and note down the text next to the quit shortcut (e.g. Quit Google Chrome)
- Find the application’s domain in the defaults system by running this from the command line (with “-i” we’re ignoring case and finding this more quickly):
defaults read | grep -i “chrome”
- In the result to the command above look for the application’s domain which looks similar to internet domains only in reverse (e.g. com.google.Chrome)
- Now reconfigure the shortcut by using the application’s domain, the shortcut text and shortcut definition:
defaults write com.google.Chrome NSUserKeyEquivalents ‘{ “Quit Google Chrome” = “@$Q”; }’
- Restart the application for the change to take effect.
In case you want to define a different shortcut, use the following special characters for using Command (Apple sign), Option, Shift and Control buttons:
@ - Command (Apple sign)
~ - Option
$ - Shift
^ - Control
After running all the above 5 steps correctly, you should have changed the shortocut for quit operation from Command+Q to Command+Shift+Q. Changes you make in defaults system will also remain active after restarting your Mac.
Here’s the similar change I’ve made on my Mac to prevent Eclipse from accidentally quitting on me (by redefining the quit shortcut to Cmd+Control+Q):
defaults write org.eclipse.Eclipse NSUserKeyEquivalents “{ ‘Quit Eclipse’= ‘^@Q’; }”
To assign Quit Eclipse shortcut to Cmd+Shift+Q you would need to escape $ sign because of the way shell parses the command line (to access reference environment variables and command parameters):
defaults write org.eclipse.Eclipse NSUserKeyEquivalents “{ ‘Quit Eclipse’= ‘@\$Q’; }”
Other signs you do not need to escape.



