How a Developer Fell in Love with Keyboard Maestro
You may have heard that I’ve been getting more in to automation recently, specifically automating more of my work and personal macOS environments. There are countless apps and tools and plugins and widgets for this on the Mac and over my 20 years using the Mac I have ignored all of them. Why? Because I can code, dammit! I don’t need a menu bar filled with little icons that are the windows to little ram-munching services when I can just write a bash script or even my own Mac app to do what I need!
So what changed? Nothing! I can still code and I still don’t want a bunch of little specialized apps running all the time…but I have seen the light on one automation app in particular.
Why am I writing this? It turns out that I fell in love with Keyboard Maestro.
Yes, on it’s face it’s a drag and drop way to create automations, making it the Mac automation Swiss Army knife, but even if you can code, it is extremely valuable. Here are a few reasons, and after that I’ll run through a few of my favorite automations.
Little Scripts Everywhere
I’ve been writing little automation scripts for decades now and they have ended up any number of places over the years, like in Documents, or ~/bin, or in Automator, or a local git repo somewhere. Even if I was diligent about keeping everything in a single directory, over time and when switching hardware, some scripts are lost, some are kept, and some are kept but the context is lost. Scheduling scripts is also an issue. Unix systems, such as macOS can use cron jobs, but they don’t sync or migrate to the next computer or are simply forgotten.
Keyboard Maestro has become a single place for all macOS automation scripts to live. Scripts are embedded in to macros, macros can be scheduled, and it all syncs via your preferred file syncing solution.
Write Once, Run Everywhere
Having all my scripts in one place has another side benefit, which is the kismet of “Oh wait, that script I wrote for work would also work really nicely on this project too!” When all of your scripts are in one place, it’s way more likely to have those little epiphanies.
Keyboard Maestro gives you the ability to group macros in to folders. Some folders can be set specifically for a single application, other group folders can be set to only be active on one or more computers. It’s really helpful and allows you to share some scripts and not share others.
Chasing UX Automation
It’s one thing to write a script that copies a file to a remote server or API, but writing scripts that automate the UI of your computer can be fraught. APIs, resolution, window commands, all change and will break your script causing you to spend hours trying to figure out the new best way to position a window in the top right corner of your second monitor. Keyboard Maestro functions as an abstraction layer for interacting with your macOS UI.
Yes, you can use AppleScript but the thing is…
AppleScript Displeases Me
AppleScript is weird. To be more precise, in an effort to make a programming language more like a written language, AppleScript’s APIs are best described as unguessable and I’d like to avoid spending hours on Google to try and find out the best way to take the first element from and array and send it to a specific and less than documented Mac app.
Let’s talk automation examples, shall we?
It’s impossible to write anything about automation without some segment of your readers to immediately scream out “SHOW ME WHAT YOU’VE AUTOMATED!” Everyone knows that automation people need a steady stream of automation suggestions fed to them or they die, which is terrible. Plus, after their dead no one knows how to turn off that thing they setup where the lights flash red when the doorbell rings and it’s super annoying.
Automated Setups or “Modes”
Having a keyboard shortcut, or in my case a button on my Stream Deck, open a series of windows for you is an extremely common use case, but it’s common because it’s really useful! I have several “modes” on my work and personal Macs. Below you can see an example of my “Start” mode that allows me to clear my windows and reset at the beginnning of the day to review Slack, email, my calendar, my notes, and a web browser.
(Yes, that is my current Mac wallpaper.)
Google Cast / Catt
I have three monitors on my desk and a TV mounted on the wall to the left of my desk and I really love the idea of treating that TV as a fourth monitor. I threw a Google Cast device on that TV and installed the command line tool catt. “catt” is an acronym for “Cast All The Things" and I think that’s a nice succinct description.
❯ catt -h Usage: catt [OPTIONS] COMMAND [ARGS]... Options: -d, --device NAME_OR_IP Select Chromecast device. --version Show the version and exit. -h, --help Show this message and exit. Commands: add Add a video to the queue (YouTube only). cast Send a video to a Chromecast for playing. cast_site Cast any website to a Chromecast. clear Clear the queue (YouTube only). del_alias Delete the alias name of the selected device. del_default Delete the default device. ffwd Fastforward a video by TIME duration. info Show complete information about the currently-playing video. pause Pause a video. play Resume a video after it has been paused. play_toggle Toggle between playing and paused state. remove Remove a video from the queue (YouTube only). restore Return Chromecast to saved state. rewind Rewind a video by TIME duration. save Save the current state of the Chromecast for later use. scan Scan the local network and show all Chromecasts and their IPs. seek Seek the video to TIME position. set_alias Set an alias name for the selected device (case-insensitive). set_default Set the selected device as default. skip Skip to end of content. status Show some information about the currently-playing video. stop Stop playing. volume Set the volume to LVL [0-100]. volumedown Turn down volume by a DELTA increment. volumeup Turn up volume by a DELTA increment. write_config DEPRECATED: Please use "set_default".
I then made a series of macros that are based on bash scripts that make catt commands targeting my Office TV:
- Take the URL on my clip board, and if it’s YouTube or Vimeo send the URL to the TV to play as a video, otherwise send it to the TV to be displayed as a webpage.
- Display the Studio71 system status page on the TV
- Shuffle and play my YouTube Watch Later playlist on the TV.
- Pause, Stop, and Skip
- Display a cyberpunk “pew pew” map on my TV.
Quick File Sharing
There are times when I need to fill my role as “typical engineering manager” and send a screenshot of a broken application with “This doesn’t work.” written on them in pink Comic Sans font. When I do, I take a screenshot and then I need to open a browser or Slack to drag it in a few times throughout the day. I simplified this workflow by making a Keyboard Maestro macro that I have assigned to the right click menu of images via Service Station. When you click the action, my macro takes the file, generates a hash, uploads it to the Studio71 asset server (I have a different version of this for my personal files), and then puts the link in my clipboard, which I can immediately paste in to anything.
I have so many more macros and I have a list of others I want to experiment with, but I’d love to hear your automation ideas, successfully implemented or otherwise.
Hit me up: @thatmikeflynn
A Decade of Clojure at Studio71
What is Clojure and why did it fit for Studio71? Clojure is a programming language (a dialect of Lisp) that excels at concurrency and data processing. Clojure runs on top of Java so it’s runs in all of the places Java runs and can use all of the Java libraries already out there (hello, Google and AWS libraries!Read more
The macOS Privacy Settings Deleted My Backups
The other day I logged in to my NAS to find that all of my backed up media files were gone. No errors, the drives were fine, the directory was there, but the files were gone. Thankfully it wasn’t a freak out moment as I had my originals and my other backups, but it was a mystery.Read more
Building a Mastodon Client in to my Cyberpunk SSH App
Let me quickly get you up to speed: I wanted to build a website for my hacker projects, but instead of a website I ended up building an SSH app (because I’m weird). Basically, instead of visiting it in your web browser you have to open your terminal, run an SSH command, and then you use text commands to play with the application, read about my projects, etc.Read more