Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
hammerspoon cmd+q twice
-- Press Cmd+Q twice to quit
local quitModal = hs.hotkey.modal.new('cmd','q')
function quitModal:entered()
hs.alert.show("Press Cmd+Q again to quit", 1)
hs.timer.doAfter(1, function() quitModal:exit() end)
end
local function doQuit()
local res = hs.application.frontmostApplication():selectMenuItem("^Quit.*$")
quitModal:exit()
end
quitModal:bind('cmd', 'q', doQuit)
quitModal:bind('', 'escape', function() quitModal:exit() end)
@kvndrsslr
Copy link

kvndrsslr commented Feb 8, 2021

Variant without modal

-- Press Cmd+Q twice to quit

local lastCmdQ = 0

local function doQuit()
    local interval = hs.timer.secondsSinceEpoch() - lastCmdQ
    lastCmdQ = hs.timer.secondsSinceEpoch()
    if interval < 1.5 then
        local res = hs.application.frontmostApplication():selectMenuItem("^Quit.*$")
    end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment