Skip to content

Instantly share code, notes, and snippets.

@rstacruz
Last active January 23, 2025 04:41
Show Gist options
  • Save rstacruz/34893af9ff16e9e4bbfd79f998a66fc1 to your computer and use it in GitHub Desktop.
Save rstacruz/34893af9ff16e9e4bbfd79f998a66fc1 to your computer and use it in GitHub Desktop.

Revisions

  1. rstacruz revised this gist Jan 23, 2025. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion launcher.lua
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,7 @@ 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"
    @@ -22,7 +23,7 @@ local LAUNCHER_APPS = {
    { key = "s", app = "Slack" },
    { key = "z", app = "zoom.us" },
    { key = "f", app = "Finder" },
    { key = "b", app = "Spotify" },
    { key = "p", app = "Spotify" }, -- [p]layer
    { key = "a", app = "Obsidian" },
    }

  2. rstacruz revised this gist Jan 23, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion launcher.lua
    Original file line number Diff line number Diff line change
    @@ -59,7 +59,7 @@ end

    local function setup()
    bindLauncherKeys(LAUNCHER_APPS, { mods = MODS })
    bindLauncherKeys(LAUNCHER_APPS_SHIFT, { mods = SHIFT_MODS)
    bindLauncherKeys(LAUNCHER_APPS_SHIFT, { mods = SHIFT_MODS })
    end

    return { setup = setup }
  3. rstacruz revised this gist Jan 23, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion launcher.lua
    Original file line number Diff line number Diff line change
    @@ -17,7 +17,7 @@ local LAUNCHER_APPS = {
    { 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" },
    { key = "m", app = "Microsoft Outlook", label = "Outlook" }, -- "[m]ail"
    { key = "b", app = "Bruno" },
    { key = "s", app = "Slack" },
    { key = "z", app = "zoom.us" },
  4. rstacruz revised this gist Jan 23, 2025. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion launcher.lua
    Original file line number Diff line number Diff line change
    @@ -18,7 +18,7 @@ local LAUNCHER_APPS = {
    { key = "t", app = "Ghostty" }, -- "[t]erminal"
    { key = "w", app = "Firefox" }, -- "[w]eb"
    { key = "m", app = "Microsoft Outlook", label = "Outlook" },
    { key = "c", app = "Bruno" },
    { key = "b", app = "Bruno" },
    { key = "s", app = "Slack" },
    { key = "z", app = "zoom.us" },
    { key = "f", app = "Finder" },
  5. rstacruz revised this gist Jan 23, 2025. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion launcher.lua
    Original file line number Diff line number Diff line change
    @@ -24,7 +24,6 @@ local LAUNCHER_APPS = {
    { key = "f", app = "Finder" },
    { key = "b", app = "Spotify" },
    { key = "a", app = "Obsidian" },
    { key = "p", app = "Google Chrome" }, -- "[w]eb"
    }

    local LAUNCHER_APPS_SHIFT = {
  6. rstacruz created this gist Jan 23, 2025.
    66 changes: 66 additions & 0 deletions launcher.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    -- 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 = {
    { 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" },
    { key = "c", app = "Bruno" },
    { key = "s", app = "Slack" },
    { key = "z", app = "zoom.us" },
    { key = "f", app = "Finder" },
    { key = "b", app = "Spotify" },
    { key = "a", app = "Obsidian" },
    { key = "p", app = "Google Chrome" }, -- "[w]eb"
    }

    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 }