How I reimplemented my long lost keybindings on MacOS

by Jared Norman
published April 21, 2020

Having used MacOS, Windows, and Linux on the desktop for significant amounts of time, I can confidently say that the longer I use any one of them, the more I miss my favourite things about the others.

Since I’ve been on MacOS pretty much exclusively since I started Super Good, I’ve been missing one specific thing about my Linux desktop setups more and more.

The Problem

On non-Linux desktops I rely on cmd-tab/alt-tab heavily for window switching; I do something in my terminal (where my editor is) then hit cmd-tab to switch back to the previously active window, which I hope is my browser, to see the results. This would work great if I only ever had two windows.

Unfortunately I sometimes use other apps, so I can’t rely on the ordering of my windows. This means switching by clicking in the dock, inspecting the cmd-tab on screen display, or remembering how many “apps ago” Slack is when I try to switch to it.

None of these options are all that bad or even particularly slow, but unfortunately/fortunately for me, I know there’s a better way.

A Better Way

Linux is endlessly customizable. If you love the idea of productivity, but hate being actually productive, you can spend your time carefully crafting the exact perfect desktop environment for yourself. I’ve done this dozens of times and still haven’t figured out what “perfect” is. I will never get this time back.

On my Linux desktops I’ve almost always used a window manager that gave me the super power to switch directly to my most used applications. This saves me from maintaining a mental stack of what applications I’ve used recently in order to press cmd-tab the correct number of times.

One way I’d do this (it varied slightly from setup to setup) was to keep each of my most used applications alone on a virtual desktop and use shortcuts to swap between them:

  • mod-1 for the first desktop (web browser)
  • mod-2 for the second desktop (terminal)
  • mod-3 for the third desktop (chat apps)
  • mod-4 for the fourth desktop (music player)

Using that I could quickly switch directly to my most used apps. It would take a week or two to really get used to, but soon switching to Slack after launching particularly slow test runs would become muscle memory.

I’d tried to emulate the app switching behaviour in MacOS, but none of the solutions worked very well.


Hammerspoon is a MacOS application that enables you to write desktop automations in Lua. I originally set it up to arrange my windows correctly for my programming streams on Twitch and it only recently dawned on me that I should try to set it up for window switching.

Fortunately (unlike configuring XMonad for the tenth time) this took me almost no time to set up. You just need to put something like this in your Hammerspoon config and you’re done:

hs.hotkey.bind({"alt"}, "1", function()

hs.hotkey.bind({"alt"}, "2", function()

hs.hotkey.bind({"alt"}, "3", function()

hs.hotkey.bind({"alt"}, "4", function()
  hs.application.get("Basecamp 3"):activate()

I now use option-1 to switch to Firefox, option-2 for my terminal, and so on. Let me know over on Twitter if you found this useful or have any other good tips on how to use Hammerspoon!