DEV Community

Jake for Effective Dev

Posted on • Originally published at effectivedev.com on

Desire Paths: For When Shortcuts Don’t Cut It [macOS]

Summary: You don’t need expensive keyboards to improve convenience. Complete customizability is excellent, but we can get halfway there with simple soft-hacks. You can use system preferences and software tools to customize your keyboard to make your navigation more comfortable and help prevent errors.

Desire Paths: For When Shortcuts Don’t Cut It [macOS]

Whether you're on a computer all day or just trying to do something quickly, you've probably realized that switching between the keyboard and mouse can take a moment. Added all together, these moments can eat up a chunk of time. This wasted time is terrible for productivity and gets even worse if you touch type and manage to miss home row.

This latency is a known limitation of most modern operating systems, and as such, there is a solution: keyboard shortcuts. Keyboard shortcuts present problems as well. Most of them are designed to work for general problems and are not optimized. If you’ve ever typed Command + Tab, Tab, Tab, Tab, Tab, you know what I mean.

Remembering keyboard shortcuts can be a daunting task. Like most things, the key to remembering them is using them. Generic ones like Copy and Paste are usually pretty easy to remember. Creating custom cheat sheets for each app you use can also be quite handy. Then there's the option to customize them.

When is a keyboard shortcut not a shortcut?

Has this scenario ever happened to you? You’re switching between applications and closing them as you go. You think you have iTunes open (Did I connect my phone?!) so you go to close it using Command + Q, nice and simple. Except you just closed a window with 5+ tabs open. Oops.

All of a sudden, that “shortcut” isn’t much of a shortcut anymore. Luckily, there is a way to disable this for specific applications. If you go to System Preferences and click on Keyboard, you’ll see a Shortcuts tab. If you create a shortcut for the "Quit [Application Name]" menu item, any existing shortcut for that menu item is not triggerable. Note that you’re going to want to make sure this matches the menu item, not the name of the application. For example, when you open iTerm, it shows “Close iTerm2”, not “Close iTerm”.

Desire Paths: For When Shortcuts Don’t Cut It [macOS]
My limited but exceptionally handy tab-savers.

In my case, I added this to Safari and iTerm. I can sit in my iTerm window and press Command + Q or Command + W and nothing happens.

When is a keyboard not just a keyboard?

A few years ago, when I was working at a contact centre, I decided to purchase a mechanical keyboard. Mechanical keyboards quickly grew into a hobby, and after about five keyboards I had found my endgame, the beautiful 40% Planck Keyboard from OLKB. When is a keyboard not just a keyboard? When it is a piece of art.

One of the main benefits of the Planck is that it runs on the QMK firmware which offers endless amounts of customizability including changing the key map. I wrote an article about it, including my keymap. The Planck is a fantastic keyboard, and I learned some of my favourite “desire paths” from it.

My only issue was that I needed to move from my desk to the meeting room. I frequently found that switching between the Planck and the built-in MacBook keyboard became confusing for my hands. However, there was no way to add this functionality to my MacBook keyboard. Or so I thought.

When is a key less than a key?

If you’re a terminal junky like me, you probably use the Control key a lot. As said before, keyboard shortcuts are a great way to avoid switching to the mouse, but in the simplified, often mouse-less environment of a terminal, they become even more critical.

I could write an article on just shortcuts for Bash/Zsh. (That’s not a bad idea. Look forward to that in the future.) The majority of bash shortcuts, along with many used for terminal programs like tmux and Vim use the Control key. The notable exception is the Escape key for Vim to enter “Normal Mode”.

As a side note, Vim’s “Enter Normal Mode” shortcut is generally Escape, but Control + [ also exists which works faster.

So, if the Control key is so important, how come it is such a stretch to reach? If you think you know why, please add a comment below. Terrible placement aside, there is a solution. And a pun, but you’ll get that in a moment. Deep inside of the System Preferences, Apple does let you adjust this.

You may have noticed while using terminal-based apps that the Home Row comes up often. The home row is the position where your hands should be at rest. Being able to put the most critical keys on this row is helpful, which is why Vim loves it so much. The Home Row contains one of the most useful keys for terminal use: the Return key, as well as one of the least useful: the Caps Lock key.

The Caps Lock key is useless in this day and age unless you find yourself in YouTube comments. It’s likely one of the few keys that’s actuated more often by accident than intention. I’m sure you can see where these two areas collide. Let’s convert that prime real-estate Caps Lock into something actually useful.

In System Preferences, open the Keyboard panel and click on the “Modifier Keys…” The modal that opens gives us some customizability. We can select to set the "Caps Lock" option to the value of "Control". Here’s a gif, because it’s not 2005 anymore and static images don’t cut it.

Desire Paths: For When Shortcuts Don’t Cut It [macOS]

Okay. So we’ve upgraded some dead space. One other thing you may have noticed is that there was another option in there. You can set the pressing of the Caps Lock key to an "Escape" press. Setting the "Caps Lock" setting to the "Escape" value is very tempting. If you have one of Apple’s Touch Bar MacBook Pros, "Escape" may even be a better choice. I did this for a while, and I can recommend it as much as the "Control" option. Of course, we can do one better.

Side note for Apple, if you’re reading this. I love the Touch Bar. It would do well above the function keys on a pro device though.

When is a key more than a key?

It’s about time we introduce the real star of this article, Karabiner Elements. Self-described as “A powerful and stable keyboard customizer for macOS,” I decided to put it to the test. I enjoyed the outcome, and I think you will as well.

Karabiner Elements is very similar to the “Modifier Keys…” prompt in the same way a Formula 1 car is very similar to a bicycle. In its “Simple Modifications” tab, Karabiner allows you to switch any key to act as any key. Did I mention this was the “Simple Modifications” tab?

”With great power there must also come — great responsibility!” RIP, Uncle Ben.

While there are eight tabs total, the first three (Simple Modifications, Function Keys, and Complex Modifications) are the ones we will discuss. If you wanted to, you could easily repeat the same modification, converting the Caps Lock key to a Control key when pressed.

The “Function Keys” tab is quite helpful as it allows you to change what the functions labelled on the keyboard do. Perhaps you don’t like Launchpad and want to have a regular F4 without changing the rest of them?

The “Complex Modifications” tab is where things get crazy. What if a key could do different things based on the context of its use? Here are a few examples:

Application Specific:

Perhaps your IDE forces you to use Shift + F4 but you don’t use F4 for anything. You can have Karabiner force all F4 presses inside of your IDE to be Shift + F4 for you.

Multi-Modifier Keys:

If you’ve read my post on Alfred, you may have noted that you can make advanced workflows start from a keyboard shortcut. If you’ve looked through the keyboard shortcuts in your apps, you’ll notice there aren’t a lot of options left that give you flexibility.

For example, if you cycle through the same five apps regularly, all day, your pinky finger may get tired from tabbing between apps. Let's add our own: introducing the makeshift Hyper key!

The makeshift Hyper key is technically a combination of Control + Option + Command + Shift. Pressing Control + Option + Command + Shift + C to open Slack would be kind of annoying. Well, let’s change a key to be the Hyper key. In this case, let’s set the right Command key to be our Hyper key. After updating Alfred to open apps using keyboard shortcuts, I have set the following:

  • Hyper + C to open my Slack _C_hat.
  • Hyper + K to open my _K_anban board.
  • Hyper + G to open my _G_itlab.
  • Hyper + M to open my Spark _M_ail.

Realistically, your memory is the soft limit for this.

Differentiate between modifier and lone key presses:

This customization is elegant, and probably my favourite part of Karabiner. A key can be a key when pressed by itself, but another key when used as a modifier. For example, let’s set our ill-suited Caps Lock key to be Escape when pressed alone, but count as Control when pressed with another key.

So now pressing the Caps Lock key is equivocal to pressing the Escape key. However, pressing Caps Lock + P is equivocal to pressing Control + P. Just think of the Vim possibilities!

To do this:

  1. Open the “Complex Modifications” tab in Karabiner.
  2. Click on "Add Rule".
  3. Click on "Import more rules from the Internet (open a web browser)".
  4. When the browser opens, search for "Change caps_lock key (rev 4)".
  5. Click "Import" for the option listed. Once imported, it’ll show you all the available rules to select.
  6. Find "Change caps_lock to control if pressed with other keys, to escape if pressed alone" and click "Enable" next to that.

Done!

Even More Craziness

There are even more things you can do, as well. Here are some examples:

  • Double-press a key to result in an event.
  • Press-and-hold a key to result in an event.
  • Use multiple non-modifier keys to result in an event.

The Ugly Side of Karabiner

One thing I’ve found difficult about Karabiner is that it’s documentation for Complex Modifiers is hidden under the karabiner.json reference manual menu item. Once you have created a complex modifier JSON file, you need to import it. At the time of this article, there is no way to import JSON files directly. To import the file, you need to use the URL karabiner://karabiner/assets/complex\_modifications/import?url={URL} where the {URL} is the full path to the JSON file starting with file:///, URL-encoded.

For example, assuming the file is at /Users/username/Documents/Modifier.json, we change it to file:///Users/username/Documents/Modifier.json, and then encode it as file%3A%2F%2F%2FUsers%2Fusername%2FDocuments%2FModifier.json and prefix it with the rest of the URL as karabiner://karabiner/assets/complex\_modifications/import?url=file%3A%2F%2F%2FUsers%2Fusername%2FDocuments%2FModifier.json.

Example karabiner.json file

<!--kg-card-begin: html--><!--kg-card-end: html-->

Wrapping It All Up

These changes represent my own needs. So now we have:

  • Removed keyboard shortcuts that cause more harm than good;
  • Single keyboard shortcuts to open apps and web pages;
  • Moved some of our most commonly used keys into better locations; and
  • Set up our environment to be able to do even more.

I hope that this article has given you the confidence to create your shortcuts and help speed up your work. If you have created some shortcuts, let me know in the comments below!

If you liked this content, please subscribe to the email newsletter. Also, be sure to follow @EffectiveDev on Twitter to get helpful links and tips. Thank you so much for reading, and have a wonderful week!

Top comments (0)