A Hyper Key Solution for Mac OSX Sierra

In the past I’ve mentioned how I have streamlined a lot of the everyday tasks I have to do through the use of various keyboard-centric apps such as Alfred and Keyboard Maestro. One of the linchpins of my setup is the use of something called the ‘Hyper Key’, which is essentially re-mapping the fairly useless Caps Lock to act as a super-function key, letting you trigger all sorts of shortcuts and different macros.

This particular configuration relied on two bits of software, called Karabiner and Seil. However, earlier today I was forced into upgrading from OSX El Capitan, to OSX Sierra, to fix an issue with some other apps that I was having. Of course, upon upgrade, I discovered that the Karabiner/Seil combination no longer functioned properly, and there was no real solution using the same tools. Sigh.

After a bit of digging, I discovered a way to re-enable the same functionality, albeit with a bit of jiggery pokery. Here’s how I did it:

  1. Install Hammerspoon. This is a piece of software that allows for automation, acting as an interface between a scripting engine called lua, and the OS itself.
  2. Install Karabiner Elements. This is a version of Karabiner that works with OSX Sierra. The latest DMG is available here.
  3. Under OSX Keyboard System Preferences pane, change the Caps Lock Action to ‘None’, to allow Karabiner to control it.

    Screen Shot 2016-10-28 at 21.12.04.png

  4. Set up Karabiner Elements to map the caps_lock to F18. You can also do this by adding in a config file to ~/.karabiner.d/configuration/karabiner.json, but it’s so easy to do manually that it seems overkill to go that route.

    screen-shot-2016-10-28-at-21-09-05
    How Karabiner Elements should look
  5. Now, load up a lua config file into Hammerspoon, by copying it to ~/.hammerspoon/init.lua – see below for examples.

The config file I am using is available over on GitHub here. It will re-enable the Hyper Key function for all a-z and 0-9 keys, as well as a couple of miscellaneous ones that I use, though it should be self explanatory on how to add new ones.

One thing to watch out for is that any Hotkeys set up in Alfred to launch applications with the Hyper Key don’t seem to work any longer, so for that, one way to get them to launch is to add a specific mapping in the init.lua configuration. Here’s what I’ve done to get 1Password to launch with CAPS+O:

-- Code to launch single apps that Alfred used to handle.
-- Hat-Tip: https://gist.github.com/ttscoff/cce98a711b5476166792d5e6f1ac5907

launch = function(appname)
 hs.application.launchOrFocus(appname)
 k.triggered = true
end

-- Keybinding for specific single apps.

singleapps = {
 {'o', '1Password 6'},
}

As you can see from the above, I obviously didn’t write the code to make all of this work. Credit for that goes to a combination of ttscoff and prenagha; I just tweaked it for my own simple use case and wrote this up in the hope that others might find it easy to follow.

Good luck!

Advertisements