Last active
January 23, 2025 04:41
-
-
Save rstacruz/34893af9ff16e9e4bbfd79f998a66fc1 to your computer and use it in GitHub Desktop.
Rico's hammerspoon launcher config
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
-- Rico's hammerspoon launcher config | |
-- | |
-- usage: | |
-- * press `ctrl-cmd-w` to switch-or-launch Firefox | |
-- * update the shortcuts below to your liking | |
-- | |
-- installation: | |
-- * save as ~/.hammerspoon/mods/launcher.lua | |
-- * add this to ~/.hammerspoon/init.lua: `require("mods.launcher").setup()` | |
-- | |
-- ...alternatively just paste all these directly into init.lua (without the `return`) and run setup() | |
local MODS = { "ctrl", "cmd" } | |
local SHIFT_MODS = { "shift", "ctrl", "cmd" } | |
local LAUNCHER_APPS = { | |
-- these keys are mostly on the left hand side (qwerty/colemak) | |
{ key = "v", app = "Visual Studio Code" }, -- "[v]scode" | |
{ key = "t", app = "Ghostty" }, -- "[t]erminal" | |
{ key = "w", app = "Firefox" }, -- "[w]eb" | |
{ key = "m", app = "Microsoft Outlook", label = "Outlook" }, -- "[m]ail" | |
{ key = "b", app = "Bruno" }, | |
{ key = "s", app = "Slack" }, | |
{ key = "z", app = "zoom.us" }, | |
{ key = "f", app = "Finder" }, | |
{ key = "p", app = "Spotify" }, -- [p]layer | |
{ key = "a", app = "Obsidian" }, | |
} | |
local LAUNCHER_APPS_SHIFT = { | |
{ key = "w", app = "Google Chrome" }, -- "[w]eb" | |
} | |
local function activateApp(app) | |
local win = hs.window.focusedWindow() | |
if win and win:application():name() == app then | |
-- If it's already focused, switch to next window | |
hs.eventtap.keyStroke({ "cmd" }, "`") | |
else | |
-- Else, focus it | |
hs.application.launchOrFocus(app) | |
end | |
end | |
local function bindLauncherKeys(apps, options) | |
for _, action in ipairs(apps) do | |
local label = action.label or action.app | |
hs.hotkey.bind(options.mods, action.key, label, function() | |
if action.activate then | |
action.activate() | |
else | |
activateApp(action.app) | |
end | |
if options.onactivate then | |
options.onactivate() | |
end | |
end) | |
end | |
end | |
local function setup() | |
bindLauncherKeys(LAUNCHER_APPS, { mods = MODS }) | |
bindLauncherKeys(LAUNCHER_APPS_SHIFT, { mods = SHIFT_MODS }) | |
end | |
return { setup = setup } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment