More useful macOS modifier keys πΉ
MacOS power users know the value of keyboard shortcuts, but here's something most people don't realize: those matching modifier keys on either side of your keyboard don't have to do the same thing. Mind-blowing, right? π€―
While tools like Hammerspoon traditionally treat left and right modifiers as identical (how rudeee!), I wrote an extension that recognizes them as distinct keys.
Want left option+s to search files but have right option+s to launch Spotify? Now you can! Here's how it works.
Setting up your shortcuts
When you write code like this:
The module creates a lookup table:
Watching the keypresses
When you press multiple keys together, macOS doesn't send us a neat list of which keys are pressed - instead, it uses a single number to represent all pressed modifier keys. Let's break down how this works.
Each modifier key has its own bit position.
So when you press right commandright optionm, macOS gives us 80 and m (simplified example):
We decode this number, figure out which modifiers are pressed, and combine it with the actual key that was pressed (in this case m) to create a lookup key ralt.rcmd.m. Then we check our lookup table from the previous step - if there's a matching function, we run it β¨
Other cool stuff
While launching apps with modifier keys is already neat, the module has more tricks up its sleeve:
Key release actions
Think of these like "peek" actions - press to show something, release to hide it. Perfect for:
- Temporarily unmuting yourself in meetings (for those "Wait, you're still muted" moments)
- Quick-checking your calendar without switching apps (because who remembers their schedule anyway?)
Key repeat features
You know how holding down a letter key types "aaaaa"? This works the same way for your shortcuts. Hold down your shortcut to:
- Adjust volume without giving your finger a workout
- Spam reaction emojis in Slack (because one π is never enough)
Flexible modifier binding
Sometimes you want a shortcut to work from either side of the keyboard (we don't discriminate here). Instead of manually binding to both left option and right option, you can just use option. The module handles the rest, like a diplomatic keyboard mediator.
Getting started
- Install Hammerspoon if you haven't already.
- Add the hotkeyextension.lua to your Hammerspoon config.
- Start binding functions - go nuts with dem shortcuts!
Here's how I like to organize my shortcuts: I use right Option (ralt) as my app launcher modifier, with mnemonics making them easy to remember:
- right optionb for Bitwarden
- right optiono opens Obsidian
- right optionl launches Linear
Not sure where to start? Check out my app manager config - it might give you some ideas for your own setup!
If you run into any issues or just want to share your cool shortcuts, find me on Twitter or GitHub. Always excited to help out and see what others create!
Happy hammerspooning! π₯