Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions .hammerspoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,29 @@ local apps = {
local lastApp = nil
local previousAppByKey = {}

local function areStartupModifiersReleased()
local modifiers = hs.eventtap.checkKeyboardModifiers()

return not modifiers.ctrl and not modifiers.alt and not modifiers.cmd and not modifiers.shift
end

local function afterStartupModifiersReleased(fn)
if areStartupModifiersReleased() then
fn()
return
end

local timer = nil
timer = hs.timer.doEvery(0.02, function()
if areStartupModifiersReleased() then
timer:stop()
fn()
end
end)
end

local function bindAppLauncher(key, app)
hs.hotkey.bind(hyper, key, function()
local function launchOrToggleApp()
local frontmost = hs.application.frontmostApplication()

if frontmost and frontmost:bundleID() == app.bundleID then
Expand All @@ -47,6 +68,12 @@ local function bindAppLauncher(key, app)
end

hs.application.launchOrFocusByBundleID(app.bundleID)
end

-- Delay app launch/focus until startup modifiers are released so apps do
-- not see held Shift/Option/Command/Control during launch.
hs.hotkey.bind(hyper, key, function() end, function()
afterStartupModifiersReleased(launchOrToggleApp)
end)
end

Expand All @@ -57,4 +84,4 @@ end
-- Special actions
hs.hotkey.bind(hyper, "\\", hs.reload)

hs.alert.show("Hammerspoon config loaded")
hs.alert.show("Hammerspoon config loaded")