Productivity Apps: Keyboard Maestro

keyboard_maestro_logoI’ve had this article on the back burner for almost three years now, but for the next thrilling instalment of my productivity app blogs, I’ll be turning to look at Keyboard Maestro.

Don’t let the somewhat dated website put you off, the app itself is unbelievably powerful. I have to admit to being wary when I first tried it out. The learning curve is steep, and the documentation pretty unclear – especially when compared to the other productivity apps that are available. However, after months years of sustained use, my feelings towards Keyboard Maestro have completely changed. It’s tough to get into, but so worth it. I honestly don’t know what I would do without it at this point.

So if Keyboard Maestro is so great, why did it take me so long to publish this? Well, there’s a few reasons. Firstly, there aren’t so many general use cases for Keyboard Maestro – at least not for me. Instead, it’s an app that’s best for repetitive tasks that are very specific to each user’s needs, which makes it difficult to give good examples. Secondly, it’s an app that you tend to set up and forget… before rediscovering it later on when your needs have changed, and you realise: “Oh! Keyboard Maestro could make this way easier!”. I’ve gone through that cycle a number of times, and after rediscovering just how awesome it is, I decided to finally complete this post.

What does it do?

Okay okay so Keyboard Maestro is great, but what does it actually do?. This is a good question, as it isn’t immediately obvious. Essentially, Keyboard Maestro allows you to take any task that you have to repeat, and automates it. If you’re familiar with Alfred, think of Alfred workflows, but on steroids. The key difference is that instead of having to write Applescript for every action you want to complete (which is still an option, by the way), there are a whole bunch of options baked in. Whether that’s telling the mouse to move and click on a certain point, displaying a popup message, getting an image size, filling in a field on a website, or whatever. You get a lot of control from the get go.

Keyboard Maestro Actions
Some of the ‘actions’ available.

 

The sheer power of Keyboard Maestro is also its undoing in a way. It’s easy to look at the list of actions and wonder when you will ever use any of them. The UI is not the most intuitive, and you’d be forgiven for giving up at the beginning purely on that basis alone.

If you want to carry out simple, general tasks, then there may well be a nicer app that lets you do those things. However, that isn’t the point of Keyboard Maestro. Keyboard Maestro is there to help you automate pretty much any task that you can think of.

In addition to the automation, there is a whole host of other cool features that you can do a deep dive into – such as an extensive multi clipboard manager, application switcher, and others – but for me the real glory lies in the macros.

What can it do for me?

 

One of the biggest hurdles to starting off with Keyboard Maestro is working out exactly what you’ll use it for. It takes a conscious effort to work out what tasks you could automate – which isn’t necessarily something you thought was possible beforehand. Once you do sit down and give it some attention though, you’ll soon come up with plenty. Do you have to fill out specific fields on a website more than once? Use a macro. Do you need to convert HTML to markdown? Use a macro. Need to extract URLs from a big block of text? Macro. The possibilities are endless.

As part of my job, I regularly have to review and respond to reports about different websites using a helpdesk system. Each one (generally) requires me to:

  1. Find the website URL in the e-mail and open it.
  2. Decide what to do.
  3. Note down the action taken in certain circumstances.
  4. Reply by copying a specific part of the original message, and quoting it back in a certain format before providing an appropriate response.
  5. Select a certain option to mark the issue as ‘Resolved’ or ‘On Hold’.

All of these steps are fairly straightforward, but a lot of time is taken up by clicking through the same tasks for each – even when I use a textexpander or snippet manager like Alfred. Sometimes the URLs are jumbled up and I need to fix them before opening or responding, or they are buried in huge blocks of text… etc. However, with Keyboard Maestro, I can reduce this all to a couple of key presses, with a couple of macros doing all of the following:

  1. Extracting all of the URLs from the messages, and opening them in new windows.
  2. Pasting the URLs in the correct quoted format at the top of the reply, along with the appropriate response.
  3. Adding whatever notes needed to track the action taken in a specific field.
  4. Marking the issue Resolved or On Hold as appropriate.

The only thing Keyboard Maestro doesn’t do is decide what action to take – which is just as well really, for a variety of reasons!

Like many of the examples, that one is very specific, but it demonstrates a bit of how granular and useful Keyboard Maestro macros can be – and will hopefully get you thinking about your own use cases. Here are some other more general tasks I regularly deploy macros for:

  • Inserting a URL wrapped in a href tags.
  • Pasting text with different styles of quotes depending on the situation.
  • Parsing blocks of text to extract URLs and/or e-mail addresses.
  • Getting ID numbers from long URLs.
  • Pasting items in a bulleted or numbered list automatically.
  • Filling out forms online.
  • Copying the current URL from my browser window (and doing stuff with it).

The most powerful and useful ones are those that have very specific, work related use cases. With a bit of imagination, you’ll come up with your own, so I’d encourage you to give it a bash.

Triggers

To wrap this up, I wanted to highlight one more feature of Keyboard Maestro that makes it stand out from other productivity apps. For those veterans amongst us who regularly make use of workflow improvements, it’s easy to run out of hotkey assignments, and Keyboard Maestro has a bunch of different ways to solve that problem. First off is the use of ‘palettes’, which lets you assign the same hotkey to different macros – and then select them from a menu – or to activate different hotkey sets depending on what you’re working on that day.

If you already use Alfred, Keyboard Maestro is a brilliant complement, rather than a replacement in this way too. There is a specific Alfred workflow that lets you search and trigger Keyboard Maestro macros from the Alfred search bar, which is incredibly useful for those that you may use occasionally, but don’t want to dedicate a precious hotkey to: Alfred Maestro.

Finally, triggers aren’t just confined to mere hotkeys. Oh no. Pretty much any event you can think of can kick off a macro. If you want certain changes to happen when you connect to a particular WiFi, you can make that happen. Execute commands remotely by running Keyboard Maestro on a server? Why not. Run certain checks when a USB device is plugged in? Easy. You can even have Keyboard Maestro react to MIDI notes and values, which opens up a whole world of interesting hardware controllers aside from the keyboard… something I’ll be exploring in the next post.

In the meantime, go forth, and automate!

 

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!

Regex E-Mail String Matching

Recently, I was playing about with Keyboard Maestro – a powerful (Mac) tool to automate tasks that you have to do on a regular basis. It seems daunting at first, but has proved to be pretty useful.

One of the the things I wanted to achieve was to be able to strip out a whole pile of data to return just the e-mail addresses, rather than have to go through them manually.

In order to do that, I needed a Regex (regular expression) pattern that would match e-mail addresses, with all of the weird formats they take: multiple TLDs, periods and dashes in the alias… and not to forget the plus sign that lets you create additional handles in GMail.

I looked around the web but didn’t find any patterns that did what I wanted. There were a few, but most seemed based on e-mail validation rather than filtering the address out of a bigger data set. So, I created my own:

\b([A-Za-z0-9%+._-])+[@]+([%+a-z0-9A-Z.-]*)\b

I’ve been using it for a couple of weeks and haven’t come across any addresses that it hasn’t picked up correctly yet. If you spot any, give me a shout in the comments below.

You can test out the expression for yourself over on the incredibly useful site regexr.com.