I’m the king of hitting random shortcut key combinations and doing unexpected things and often accidentally close a tab or the entire window in Google Chrome while editing some content on one of my websites. Which means having to go back and re-write that content… I’d have enough of that so decided to work out how to remap the Cmd+Q and Cmd+W keys so I could no longer accidentally shut down a tab or window when really meaning to copy n paste or select all (or some other well meaning shortcut).
Setting Application Shortcuts on Apple OS X
It’s possible to remap any keyboard shortcut for all applications and a single application using the system preferences. All you need to do is take note of the name from the application’s menus and then create a new shortcut for it.
The first screenshot below shows the default keyboard mapping for Google Chrome on Mac for the "Chrome" menu:
What I wanted to do was change the shortcut for "Quit Google Chrome" on this menu, and "Close Tab" on the "File" menu. There’s also "Close Window" but it’s a bit more of an awkward keyboard comabination (Cmd+Shift+W) and I don’t think I’ve yet managed to trigger that one.
There is a useful option in Chrome to "Warn Before Quitting" – use your mouse to click it to turn the option on, and then you have to hold down Cmd+Q for a couple of seconds before Chrome will quit. This is quite useful, but it still won’t stop me closing tabs by mistake so since I’m change Close Tab I may as well change Quit App too.
System Preferences -> Keyboard -> Keyboard Shortcuts -> Application Shortcuts
So navigate to System Preferences, select Keyboard, then the Keyboard Shortcuts tab, then the Application Shortcuts option in the list on the left. This will show you your current set of shortcuts, which when nothing additional has been defined will look like this:
Adding the new shortcut
To add a new shortcut, click the + button which I’ve highlighted with a red box in the screenshot. A new dialog will appear which looks like the one below (but without the fields populated):
The Application drop down box lets you choose whether to make the shortcut apply to all applications or just a specific one. There doesn’t appear to be a global way to change the Quit option because the text is different in all apps. For example it’s "Quit Google Chrome" in Chrome and "Quit TextWrangler" in TextWrangler.
Other commonly named shortcuts (for example "Copy") should be able to be set globally, but I haven’t tried that myself (and perhaps there’s another way?)
The Menu Title box needs to have the text typed in the exact same as it appears on the menu. So in my examples it has to say "Quit Google Chrome" and "Close Tab" othwerwise it won’t work.
Finally enter a shortcut combo into the Keyboard Shortcut box and click Add.
Menus are updated
The new shortcuts created work immediately; there’s no need to restart the application if it’s already running. The final screenshot below shows the newly revised Google Chrome menu with the new shortcut which uses Control+Q to quit instead of Cmd+Q:
I’ve been using these revised shortcuts for a few days now and it’s a little odd getting used to it; I always use the keyboard to close apps and windows/tabs and I sometimes find myself trying to use Control+Q/W in other apps too, but at least I can’t accidentally close the wrong tab/window in Chrome now and lose my work.
You can of course change the shortcut keys for any application and for any menu option (including those which might not already have key mappings); I’ve just used Chrome in this post as an example because that’s what I needed to change.