OS X includes all kinds of tools to help speed up your Mac’s workflow – scripting, keyboard shortcuts and Automator among them. But the venerable utility Keyboard Maestro can be more useful, in more different ways, than any of those built-in tools.
Keyboard Maestro is a strange beast. At first glance, many people think it’s just a more advanced version of OS X’s built-in text replacements, a competitor to TextExpander and Typinator. But if you dig just a bit deeper, you’ll find it’s really more of an alternative to automation tools like Applescript or Automator, with the ability to launch all kinds of actions with a variety of triggers (not just from the keyboard).
In concept, the app is pretty simple: You pick a triggering event and set one or more actions that will take effect when triggered. Those actions can be as simple as opening a particular app or inserting some text when a key combination is pressed – but that would hardly make the app worth its US$36 price tag. Where Keyboard Maestro really earns its keep is when you use triggers other than keyboard shortcuts (there are 16 different types), and when you define actions conditionally, so the action taken depends on specific circumstances.
I’ve come up with eight examples of the kind of non-obvious things Keyboard Maestro can do, which beginners to the app often overlook or don’t imagine. It’s not a complete list by any stretch, but it’ll give you an idea of what the app can do.
Open an app when inserting a USB device
Whenever you connect a specific USB accessory to your Mac, Keyboard Maestro can detect it and do whatever you want as a consequence.
To start, create a new macro (use the Global macro group so it will work in any app). Choose USB Device Trigger from the list of available triggers, and select This USB device. Plug the device in question in and Keyboard Maestro should automatically add its name to the device name field.
The action could depend on the type of device you’re dealing with.
So, for example, you could create a macro that launches your scanner software whenever you plug in the scanner. Follow the steps above and click on New Action at the bottom of the new entry. Pick Open, then Open a File, Folder or Application from the action selection interface and locate your scanner app.
Or, if you regularly back up your Mac using a disk-cloning app like Carbon Copy Cloner or Superduper!, you could set Keyboard Maestro to launch that app when you insert your clone disk, and even set it to start the cloning.
The trick here is that, because Superduper! can’t be scripted, your macro has to include simulated button presses. It also needs a couple of short pauses to let the system first mount the drive and then make sure Superduper! is launched. The macro action flow could go like this:
When the USB device named name of your external drive is attached: Pause for two seconds; open Superduper!; pause another two seconds; activate Superduper!; press the Copy Now button; press the Copy button.
Autosave in Microsoft Word
While Microsoft Word remains a standard app in offices around the world, it surprisingly lacks even basic autosave and it does not support OS X’s versioning system. If you’ve ever experienced that sinking feeling when Word crashes and you hadn’t saved your document for a long time, when the recovery feature doesn’t work and you’ve just lost hours of work, this macro is for you.
Make a new macro in the Global group. Now add two Application triggers: First, that Microsoft Word is active; set that one to repeat every minute or so. Set a second trigger to when Microsoft Word deactivates. This causes the macro to save your open Word doc whenever you switch to another application.
Then add the action Execute, then Execute an Applescript. Copy the following script code into the text field that appears:
tell application "Microsoft Word" if it is running and name of active document does not contain "Document" then save active document end if end tell
This tells Word to first check that it is running and that the name of the active document (the frontmost open document) doesn’t include the word
Document; if those two conditions are met, then the macro saves the active document. That second condition is there so the macro doesn’t trigger when you’re working in a new, unsaved document; without it, you wouldn’t be able to switch away from Word until you’ve saved the document.
Automatically connect VPN on insecure networks
If you care about your privacy, you should consider using a VPN service when connecting to the internet from an open or semi-open wireless network, such as those you find in coffee shops and airports. You can use Keyboard Maestro to automatically connect your VPN whenever you’re on an insecure network.
Make a new macro under the Global group and pick Wireless Network Trigger. Pick Any Wireless Network from the first drop-down and Is Connected from the second so that the script will test every network you connect to.
Add an action and pick If Then Else from the Control Flow group. Change the first drop-down to If None Of The Following Are True, then click New Condition. Choose Wireless Network Condition and add The Wireless Network With Exact Name, select the name of your home network, and Is Connected. Continue adding similar conditions for all the Wi-Fi networks you regularly connect to.
Finally, add the action Execute Applescript and add the following script:
tell application "System Events" tell current location of network preferences connect service "Your-VPN-Service" end tell end tell
Replace Your-VPN-Service with the exact name of your VPN service as listed in System Preferences Network pane. If you have several different VPN services, you can further enhance the macro by adding conditionals to determine which service to use.
Open a website at a set time
If you have any websites you regularly check, especially at certain times, you can use Keyboard Maestro to do it for you. So, for example, you might like to check the results for last night’s games, some stock quotes and a forum thread on a site that doesn’t offer automatic email updates.
To do so, make a new macro in the Global group and pick Time Trigger. Set the time and days of the week you want the workflow to run.
Next, add a new action and pick Safari Control then New Safari Tab or Google Chrome Control and New Google Chrome Tab. Copy and paste the address to the site(s) you want to have opened at the specified time.
Finally, pick Activate a Specific Application from the Application Control group, then choose Safari or Chrome. Uncheck All Windows and Reopen initial windows. Now the browser should open and stay active whether it was running or not while opening your site.
Keep your social networking in check
Facebook, YouTube, Instagram, Tumblr, Twitter: the list of distractions that can easily suck up your time and leave you with piles of work and regret at the end of the day grows ever longer. If you haven’t reached the level of focus and self-discipline of a Buddhist monk just yet, you can use Keyboard Maestro to keep yourself from wasting hours on social networks when you should be working.
Make a new macro in the Global group, and pick Time Trigger, then While Logged In and choose how frequently the macro should trigger. (I chose every two minutes.) I also set the trigger to run between 8:30 a.m. and 5:30 p.m. seven days a week; adjust that as you wish.
For the action, I chose to activate MacJournal, the application I use to write with. I also added an additional action and picked Hide Other Applications from the Application Control group to hide all other applications.
The result is that you can still easily do some quick searches in Safari or even catch a couple of tweets. But every two minutes you are reminded to get back to work by hiding all other apps and activating MacJournal (or whatever your favourite work app is).
If you work in a bunch of apps, you can adjust the macro to hide just a few specific apps – web browsers, Twitter clients and the like.
Open in Chrome
Many of us keep several browsers around, either for different tasks or simply because some websites seem to work better in one browser than another. If Safari is your main browser but you sometimes find you need to open a site in Google Chrome, you can create a keyboard shortcut to instantly take the frontmost tab in Safari and open it in Chrome.
Make a new macro, either putting it in the Global group or – if you prefer to only make it run while Safari is the frontmost application – in a new macro group set to only work in Safari.
Pick a Hot Key Trigger and choose one that’s easy to use and remember. If you want to make sure the shortcut isn’t already in use, you can try it first. Shortcuts that use the Control and Option keys are much less common than shortcuts that use Command and Shift. The same goes for the F-keys (though you normally have to use Fn to activate those).
Add an action and choose If Then Else from the Control Flow group. In the action, choose All Of The Following Are True, This Application, Safari Is Running. This makes sure Safari is running before trying to open its frontmost tab in Chrome.
Next, add the following three actions one after the other:
- Open > Open a File, Folder or Application and navigate to and pick Google Chrome.
- Google Chrome Control > Wait For Google Chrome to Finish Loading
- Google Chrome Control > New Google Chrome Tab > Choose With URL: %SafariURL%
%SafariURL% is a special token that automatically finds the address of Safari’s frontmost tab/window. Keyboard Maestro includes a long list of such tokens that can paste anything from today’s date to the position of the mouse pointer on the screen and the name of the trigger that triggered the macro.
Set actions for special mouse buttons
If you’re a traditionalist who still prefers to use a mouse, chances are you have a mouse with buttons that aren’t really used in Mac applications. With Keyboard Maestro, you can make them useful.
For this macro, I’d suggest you make a new macro group called Mouse Controls or something similar, in order to group the different button triggers together. Now make a new macro in that group and pick Device Trigger, then This Device Key and then press the button you want to set an action for. In my example, I clicked the left extra button on a Logitech G3 mouse, which shows up in Keyboard Maestro as USB Gaming Mouse Button 4.
In this example, I’m going to make the extra buttons on the left and right of the mouse go backwards and forwards in Safari and Finder, but change the brush size in Photoshop.
Start by adding the Control Flow action If Then Else. Pick All Of The Following Are True and choose This Application: Safari Is At The Front and the action to Interface Control, then Type A Keystroke; press Command-Left Arrow. This is the shortcut to go backwards in Safari.
For Finder, add another identical action but choose Finder and make the keystroke Command-[.
Now add another If Then Else action with the same conditions, but pick Adobe Photoshop as the app and set the keystroke to
[ (the default shortcut for reducing the brush size in that app).
Repeat the same procedure in a new macro for any other buttons. The same thing works for special buttons on keyboards that don’t have a set function in OS X, and even for some buttons on other USB accessories. As long as Keyboard Maestro detects the press of a button, you can use it.
Use MIDI devices to control your Mac
This tip is a little more out there, but if you make music with your Mac, either for fun as an amateur with Garageband or professionally with Logic Pro or other pro apps, you probably have a MIDI keyboard of some kind. These are great for making music, but can actually be used with any app if you have Keyboard Maestro.
The trigger you’re looking for is called MIDI Trigger. Pick This Midi Note and just play a note on the keyboard. You should usually choose any device and any channel to make sure your macro triggers no matter which port you’ve plugged the keyboard into and what channel it’s set to.
With a full-size keyboard, you have enough keys to make shortcuts to all menu items in every app you’re likely to use. You could even start colour coding or labelling the keys for these extra functions.
Apart from making easy to access one-key shortcuts, you can also use this trigger to write notes even if you don’t have a music app that does it for you. Make a macro in a group restricted to, say, Microsoft Word, and make it write down the notes you’re hitting while playing on the keyboard.
But, wait, there’s more! Here are a few ideas for other Keyboard Maestro macros that you could assemble yourself.
Pull a prank: Install Keyboard Maestro and set a macro to run every time the user presses some common keyboard shortcut, such as Command-Q. Make it run an Applescript that does something spooky but totally harmless, such as:
say "I'm sorry Dave, I'm afraid I can't do that".
Set up your Mac for different locations: You could have the Mac set volume to 0, open Mail, hide Safari, and quit Skype whenever you connect to your work Wi-Fi.
Automate filling in website forms: With the Safari and Chrome control actions, you can cook up some pretty advanced macros to make web based work less tedious.