Skip to content

Instantly share code, notes, and snippets.

@numist
Created June 11, 2024 04:42
Show Gist options
  • Save numist/b2f9e3ad62a7d6ea43d438a1dc475db3 to your computer and use it in GitHub Desktop.
Save numist/b2f9e3ad62a7d6ea43d438a1dc475db3 to your computer and use it in GitHub Desktop.
Hammerspoon configuration for holdCmdQ
-- config: number of seconds to hold Command-Q to quit application
cmdQDelay = 2
cmdQTimer = nil
cmdQAlert = nil
function cmdQCleanup()
hs.alert.closeSpecific(cmdQAlert)
cmdQTimer = nil
cmdQAlert = nil
end
function stopCmdQ()
if cmdQTimer then
cmdQTimer:stop()
cmdQCleanup()
hs.alert("quit canceled",0.5)
end
end
function startCmdQ()
local app = hs.application.frontmostApplication()
if app:bundleID() == "com.apple.finder" then
return
end
cmdQTimer = hs.timer.doAfter(cmdQDelay, function() app:kill(); cmdQCleanup() end)
cmdQAlert = hs.alert("hold to quit " .. app:name(), true)
end
holdCmdQ = hs.hotkey.bind({"cmd"},"q",startCmdQ,stopCmdQ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment