One of the more irritating features of MacOS is how easy it is to quit an app with ⌘Q (CMD-Q), especially if keyboard shortcuts such as ⌘1 are being used. One miskey, and there goes your app session.

Karabiner used to be a solution, with a feature that required ⌘Q to be pressed twice before the app would quit , but the Karabiner Elements, the MacOS Sierra version, doesn’t support this.

However, there is a fairly simple(ish) way to recreate this behaviour, using Hammerspoon, a ” a desktop automation tool for OS X. It bridges various system level APIs into a Lua scripting engine”.

So, to prevent cmd-q from instantly quitting the current app do the following:

  • install hammerspoon (
  • Run Hammerspoon
    • Hammerspoon saves its config in $/.hammerspoon, and we can add our own scripts here
    • The Lua script to prevent Cmd-Q killing an app is here
    • Save the lua script as ~/.hammerspoon/double_cmdq_to_quit.lua
    • Edit ~/.hammerspoon/init.lua and add this line: require("double_cmdq_to_quit")
    • Reload config from Hammerspoon’s menu bar icon

Typing ⌘Q should now show this

and typing ⌘Q will now quit whichever app we were trying to quit.

( thanks to the good folk in this GitHub issue