14. March 2024 By Guus de Wit
Instant Application Switching with Keyboard Maestro
Introduction
Some years ago I made the switch to working on a Mac, away from Windows and Linux. As I was already used to the terminal on my old Ubuntu system, the change wasn't too big of an issue. However, I just couldn't wrap my head around one thing: how window and application management is handled on macOS. Finally, after years of having a half-working setup, I have found the perfect solution, and it’s even better than what I had before!
The Problem
Apart from having to relearn my muscle memory to press the Command key instead of the Control key, there were two missing features that I used all the time, namely window management and instant app switching. More specifically, the keyboard shortcuts for each of these.
Window Management
Window management concerns the ability to manipulate the size and location of your application windows. On Windows, pressing "Windows + Up" maximizes a window, and "Windows + Left/Right" puts it on half the screen. Additionally, holding Shift lets you move apps across monitors. But this does not apply to macOS. Even more surprising to me was that clicking the "maximize" button on an application window puts it in a new virtual space, located separately from all your other apps. This was not at all what I expected, nor what I wanted.
App Switching
The other thing that I used all the time was switching between apps with keyboard shortcuts. You've probably heard of Alt+Tab, which lets you switch between your most recent apps. That does exist on Mac (albeit with Command+Tab). However, Alt+Tab never really clicked with me. You have to press it a different number of times to activate a certain app, depending on how recently you used it.
I preferred "Windows+Any Number" instead, which activates the apps in your taskbar. I always made sure to have these in the same order, so that for example "Windows+1" would open Chrome and "Windows+4" would activate my file browser. This does have some limitations (like the apps always having to be in the same order, and only having 10 number keys), but it is rather useful. Needless to say, there is no such thing in macOS by default.
First Attempt
To still use my favorite shortcuts on Mac, I used the following setup for a couple of years. For window manipulation, I installed a specific app (I picked Rectangle, but there are plenty out there). The default keyboard shortcuts were not to my liking, so I changed them to something more familiar.
For instant app switching, I had a harder time finding a solution. macOS doesn't give you the possibility to activate a specific app, based on the position in the Dock. What I did instead was to have 10 separate virtual desktops (divided between my primary and secondary monitors) and the keyboard shortcuts "Ctrl+Number" to navigate to that space, and "Ctrl+Arrow'' to switch between adjacent ones. Now I made sure the same apps were always maximized in those spaces, and I had a somewhat workable solution.
There were some downsides:
- Again, I had to manage the position of my applications in a specific order. This time between different spaces, which is even more annoying than on the taskbar.
- Among all the new keyboard shortcuts I created, frequently some were conflicting with shortcuts for specific applications.
- When I worked on only my laptop screen, some spaces were merged into one, resulting in the numbering being off.
- The animation for switching between spaces is annoyingly slow...
The Solution
I recently came across a solution that addressed all my issues. It is fast, never conflicts with existing apps, and has zero "order" maintenance. There were two key ingredients to this solution that, when combined, gave me a way of working that I never want to be without anymore.
Global Shortcuts
The first ingredient was to only define global shortcuts that never interfere with existing applications. There's a fairly easy way to do that: just hold "Control+Shift+Alt+Command" plus any key you like for a given global shortcut. It's such an uncomfortable shortcut, that no application in their right mind would think of using it. Which makes it perfect for our use case!
The trick to make it usable in real life is to use software to remap a single button on your keyboard, to the combination of the four modifiers. For example, if you don't use the right Alt key that much, you can remap it to "Control+Shift+Alt+Command" (often called "Hyper") with just one key press. That's a game-changer! You can now create any global shortcut you want, with just a combination of two buttons. Another key you could consider for this is Caps Lock. I use this for my window management in Rectangle.
Have a look at Karabiner Elements, if you want to try this out. It can do all kinds of keyboard customizations. I don't have much experience with it, since I use a programmable keyboard that can remap keys on the firmware level directly (but that's a topic for another day).
Specific App Activations
Now, enter Keyboard Maestro[1] .Keyboard Maestro can "automate applications or websites, text or images, simple or complex, on command or scheduled. You can automate virtually anything" (according to their website).
There are hundreds of built-in actions and you can use custom scripts. These can be triggered by all sorts of events, like keyboard shortcuts, periodic cron jobs, your laptop’s power status, or even the attachment of a specific USB device. If you want to automate anything on your Mac, chances are that Keyboard Maestro can do it!
I haven't explored everything in Keyboard Maestro yet, but the action I was interested in is "Activate a Specific Application" (conveniently the very first one in the alphabetically sorted list). It turned out to be the holy grail that I had been looking for!
Weaponed with my new Hyper key global shortcut modifier, I immediately applied this action to my most used applications. If you are defining a keyboard shortcut yourself, I advise you to pick something that you can easily remember. To me, my main applications were ingrained to specific numbers from 0 to 9, after using them like that for years.
I can now instantly switch to any desired application, with a shortcut that's as short as Ctrl+Z! No need to press Alt+Tab an arbitrary number of times, no need to wait for "switching space" animations, and no need to manually maintain my applications in the correct order. Suffice it to say, I'm not switching back to my old setup any time soon! (But if I would ever want to, I could probably define a keyboard shortcut for it in Keyboard Maestro).