Feb 17, 2025
Custom Keyboard Shortcuts on macOS
I changed my workflow a bit depending on keyboard shortcuts and different desktops and found a nifty tool called Hammerspoon that allows you to create custom keyboard shortcuts. It’s a Lua scripting language that allows you to write small scripts that can be triggered by keyboard shortcuts.
Originally found at Superuser
-- Constants
MODIFIERS = {"cmd"} -- Modifiers used for app shortcuts
-- App configuration
APPS = {
{shortcut = "1", name = "Firefox"},
{shortcut = "2", name = "Alacritty"},
}
-- Bind application shortcuts
for _, app in ipairs(APPS) do
hs.hotkey.bind(MODIFIERS, app.shortcut, function()
hs.application.launchOrFocus(app.name)
end)
end
CMD + 1 will focus on/open Firefox, and CMD + 2 will focus on/open Alacritty.