mirror of
https://github.com/jimeh/dotfiles.git
synced 2026-02-19 13:46:41 +00:00
Toggle applications via global hotkeys in Hammerspoon
This commit is contained in:
38
hammerspoon/app_toggle.lua
Normal file
38
hammerspoon/app_toggle.lua
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
-- luacheck: read_globals hs
|
||||||
|
|
||||||
|
local obj = {}
|
||||||
|
|
||||||
|
function obj:bind (mods, key, name, path)
|
||||||
|
hs.hotkey.bind(mods, key, self:toggleFn(name, path))
|
||||||
|
end
|
||||||
|
|
||||||
|
function obj:toggleFn (name, path)
|
||||||
|
return function ()
|
||||||
|
self:toggle(name, path)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function obj:toggle (name, path)
|
||||||
|
local app = self.findRunningApp(name, path)
|
||||||
|
|
||||||
|
if app == nil then
|
||||||
|
return hs.application.open(path or name)
|
||||||
|
end
|
||||||
|
|
||||||
|
if app == hs.application.frontmostApplication() then
|
||||||
|
return app:hide()
|
||||||
|
end
|
||||||
|
|
||||||
|
return app:activate()
|
||||||
|
end
|
||||||
|
|
||||||
|
function obj.findRunningApp (name, path)
|
||||||
|
for _, app in ipairs(hs.application.runningApplications()) do
|
||||||
|
if app:name() == name and (path == nil or path == app:path()) then
|
||||||
|
return app
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- the end
|
||||||
|
return obj
|
||||||
@@ -15,12 +15,6 @@ hs.menuIcon(true)
|
|||||||
hs.console.alpha(0.90)
|
hs.console.alpha(0.90)
|
||||||
hs.console.behaviorAsLabels { 'moveToActiveSpace' }
|
hs.console.behaviorAsLabels { 'moveToActiveSpace' }
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
-- Require modules
|
|
||||||
--------------------------------------------------------------------------------
|
|
||||||
|
|
||||||
require('window_management'):init()
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- Load Spoons
|
-- Load Spoons
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
@@ -34,6 +28,34 @@ hs.loadSpoon('HeadphoneAutoPause')
|
|||||||
spoon.HeadphoneAutoPause.autoResume = false
|
spoon.HeadphoneAutoPause.autoResume = false
|
||||||
spoon.HeadphoneAutoPause:start()
|
spoon.HeadphoneAutoPause:start()
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- Application toggles
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
-- the end
|
local apptoggle = require('app_toggle')
|
||||||
|
|
||||||
|
apptoggle:bind({'cmd', 'alt', 'ctrl'}, 'A', 'Activity Monitor')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, '4', 'Skitch')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'A', 'YakYak')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'B', 'Postico')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'C', 'Medis')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'D', 'Wavebox')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'E', 'Emacs')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'F', 'Messenger')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'G', 'Stride')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'S', 'Skype')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'T', 'IRCCloud')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'W', 'WhatsApp')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'X', 'Calendar')
|
||||||
|
apptoggle:bind({'cmd', 'ctrl'}, 'Z', 'Slack')
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- Window management
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
require('window_management'):init()
|
||||||
|
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
|
-- The End
|
||||||
|
--------------------------------------------------------------------------------
|
||||||
hs.alert.show('Hammerspoon loaded')
|
hs.alert.show('Hammerspoon loaded')
|
||||||
|
|||||||
Reference in New Issue
Block a user