Created
September 19, 2022 18:28
-
-
Save pik4ez/5813367697fe8a9d90f1d2c64bf8957d to your computer and use it in GitHub Desktop.
Hammerspoon for fast windows switching
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
-- Globals. | |
hs.loadSpoon("ReloadConfiguration") | |
spoon.ReloadConfiguration:start() | |
local log = hs.logger.new('hammerspoon', 'debug') | |
-- Key bindings. | |
hs.hotkey.bind({"cmd"}, "[", function() | |
hs.appfinder.appFromName("Telegram"):activate() | |
end) | |
hs.hotkey.bind({"cmd"}, "p", function() | |
hs.appfinder.appFromName("Slack"):activate() | |
end) | |
hs.hotkey.bind({"cmd"}, "b", function() | |
hs.appfinder.appFromName("KeePassX"):activate() | |
end) | |
hs.hotkey.bind({"cmd"}, "q", function() | |
hs.appfinder.appFromName("wolt-mail"):activate() | |
end) | |
hs.hotkey.bind({"cmd"}, "w", function() | |
hs.appfinder.appFromName("pik4ez-mail"):activate() | |
end) | |
hs.hotkey.bind({"cmd"}, "e", function() | |
hs.appfinder.appFromName("wolt-calendar"):activate() | |
end) | |
hs.hotkey.bind({"cmd"}, "m", function() | |
hs.appfinder.appFromName("Google Chrome"):activate() | |
end) | |
hs.hotkey.bind({"cmd"}, "i", function() | |
focusAppWindowByExactName("iTerm2", "terminal") | |
end) | |
hs.hotkey.bind({"cmd"}, "o", function() | |
focusAppWindowByExactName("iTerm2", "nvim") | |
end) | |
-- Functions. | |
-- Focuses the window of the application appName with the winName. | |
-- | |
-- Uses the exact match to find the window by name. | |
-- | |
-- Limitations: in multi-monitor setups, works only | |
-- if 'Displays have separate Spaces' is turned off | |
-- in Mission Control settings. | |
function focusAppWindowByExactName(appName, winName) | |
local app = hs.appfinder.appFromName(appName) | |
if app == nil then | |
hs.application.launchOrFocus(appName) | |
return | |
end | |
local win = app:getWindow(winName) | |
if win == nil then | |
app:activate() | |
return | |
end | |
win:focus() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment