Created
June 11, 2024 04:42
-
-
Save numist/b2f9e3ad62a7d6ea43d438a1dc475db3 to your computer and use it in GitHub Desktop.
Hammerspoon configuration for holdCmdQ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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