An Interview with Peter N. Lewis
Peter N. Lewis is the developer behind Keyboard Maestro, which makes automations on macOS a breeze.
Who are you, and what do you do?
I’m Peter N Lewis. I include the N (for Neil) because I once worked out there are around 10,000 folks named Peter Lewis in the world (no idea if that is correct though), and several of them are quite famous. That said, I once walked in to a Mac tech store in Austin, TX and had someone recognise my name on my credit card and tell me that was “quite a famous name in this industry” (back in the early Internet days when I was relatively well known). I live in Perth, Western Australia, where I've been since I was 13 - before that I lived in Canada and I was born in Jamaica. I've got a fantastic wife and three kids, the youngest near the end of high school and the other two in uni. I've been writing and releasing Mac software for thirty years. I wrote a lot of early Mac Internet software, including Interarchy, and being part of what eventually became the system that maps URL schemes (like “http”) to applications. About twenty years ago I purchased Keyboard Maestro back when it was version 1, and my main focus since then has been building it into a very powerful automation tool.
How did you get interested in that?
The Internet stuff I sort of fell in to. If you were on a uni campus in the early 1990s, you started to have some access to the Internet. And if you had some access, you quickly worked out that this Internet thing was going to take over the world. But most of the tools were only available for Unix systems, so I made it my mission to build tools for the Mac to merge Mac ease-of-use and Unix Internet tools. For Keyboard Maestro, I used and relied on it myself, and it had been stuck in a kind of developer limbo for some years, so eventually I asked Michael Kamprath what his plans were, and he was not at a point where he could move it forward. So a deal was struct and I took it on.
What resources would you recommend for people that are interested in what you do?
It's hard for me to recommend much in the way of resources to learn programming, it's been incremental learning for me for a long time. I think the most important thing (as, I suspect, with any craft) is to start and keep working at it. I guess one of my favourite books on programming is Writing Solid Code by Steve Maguire, and a lot of that is for the general principle that when you find a bug, you don’t just fix the bug but figure out how you could have avoided ever writing the bug in the first place. Given the complexity of what Keyboard Maestro does, this has really served me well over the years, and I'm pretty proud that I've got the Keyboard Maestro crash rate down to around one crash per ten thousand user-days.
What software & hardware do you use?
Software wise, I don't use anything overly fancy. Mostly just Xcode, and BBEdit (because everyone needs BBEdit). Acorn for some image work. ScreenFlow for the occasional promotional videos. But Xcode alone provides pretty much everything you need to develop for macOS or iOS. Hardware wise I have a MacStudio with two large monitors attached to it. The speed of the MacStudio is nice for compile times, but that really only becomes an issue when your application is quite large. I always try to get as much RAM as I can since that is often a significant limiting factor and you can't just plug in additional RAM like you can harddisk storage.
What routines or habits help you get your work done?
I work for myself, by myself, with no clients, so motivation is a continual challenge. But the flip side can be bad too, a lot of people in that sort of situation will spend too much time working, and extra hours do not tend to produce a lot of extra results. So pretty early on I chose to limit work to “office hours”, although I also allow myself the freedom to do other things, especially when my kids were young, things like running the chess club at the primary school, or attending school carnivals and the like. On an ordinary day, my routine is to deal first with support email. Usually this doesn't take long, because as well as trying to keep bugs out of Keyboard Maestro, I consider any support queries where a customer needs help to essentially be a bug, so I ensure that anything that leads to a lot of support email gets polished out of future versions. After support email, and generally checking things like News and Mastodon, I get to “proper work”. Frequently this involves plucking something off the extremely long Wishlist list and implementing it.
Keyboard Maestro is a phenomenal automation tool for the Mac. I used to cut down on endnote errors in a book I was working on (and also speed up their creation). What are some ways you use it for yourself?
I'm glad you like it. Honestly, I think almost anyone who works on a Mac could get great value out of Keyboard Maestro. For myself, I use it a lot dealing with support email. I have a bunch of canned responses that I use in Mail, as well as more complicated macros that do things like look up a customer’s invoice from their license details, convert the invoice to a PDF and place it in the email. Similarly in Xcode, I've got a lot of macros for creating code, like adding an #import
to the top of the file, converting an enum class in to a switch statement, or selecting/resizing specific Xcode windows. And I have endless macros for filing PDF scans, switching between applications, moving windows, etc.
Your development Keyboard Maestro is unique in that it was first developed by Michael Kamprath before you acquired it in 2004. Still, it's a 20 year old tool at this point. What are some challenges that were unique to working on a pre-existing codebase?
Yes, that was definitely interesting. Working with other people’s code is not my forte, so it took some time. For version 2 it was really just a matter of finishing the work that Michael had already done, and integrating it with our licensing system, building out web pages and all that “corporate” stuff. Version 3 was a lot of structural changes, really laying the ground work for future versions, and also me getting familiar with the code base. And then version 4 was a UI overhaul, the entire UI was rewritten from the ground up, building on the structural changes from version 3. Rewriting code is always dangerous, but I guess it must have gone reasonably well as the UI for Keyboard Maestro has remained very true to that vision even fifteen years and 6 major versions later.
As a follow up, what's it like working on a ~20 year old codebase now? What are some things you wish you did differently?
A challenge. Well, not so much for me, I'm very familiar with the codebase and it's all solid Objective-C++. And in fact it all got a lot better over the years with the amazing integration of Objective-C and C++, together with ARC (Automatic Reference Counting) which means you can put Objective-C objects inside C++ containers and have C++ objects in Objective-C objects. But for better or worse Apple is moving to Swift/SwiftUI, and unfortunately Swift does not interoperate well with C++ yet. Up until now that hasn't really been a problem, but going forward it is going to start to be, and I'm not really sure how to resolve that. Hopefully the Swift/C++ story will improve, and SwiftUI will become more robust and complete and then a path forward will be easier to find. As for what I wish I'd done differently, I think the single biggest thing would be that I wish I had spent the time to implement some sort of data-driven interface generation for actions. Keyboard Maestro has a lot of actions. A lot a lot. Like 150-200. And most of them have some configuration, and that configuration is all done with bespoke UI, all created by hand. Of course, they are all designed to look similar, and indeed internally I have “lint” process that looks at the positions and placement of items in those interfaces and lets me know if something is a pixel too far to the left or whatever. But maintaining all that has a cost. If I ever decided I wanted to change something, I have to hunt through all the actions that use something similar and adjust them, and that's not good.
Before Keyboard Maestro, there was Interarchy/Anarchie in the early 90s. You've been a Mac user since the 80s. How has the Mac, and the development experience on the Mac, changed since you started? How has it improved & how has it gotten harder?
It has certainly been a wild ride! I've been through numerous development environments, including THINK Pascal, MPW, Metrowerks and Xcode. THINK Pascal was amazingly ahead of its time, and Metrowerks really saved Apple’s bacon. Xcode is a really impressive tool, though it's complexity is also pretty impressive. I don't use half the settings and facilities that Xcode offers. At the same time, macOS has gone from something that fit on a 400k floppy to something that is tens of GBs. It's pretty much impossible for one person to know it all, but now we have a lot of online resources like Stack Exchange as well as Apple’s documentation and forums to help learn each bit as you need. For me, the most frustrating thing tends to be Apple’s security systems. I understand the need for them, we live in a different world today than in the ’90s, but they cause so many problems to my customers just trying to get their work done.
What can Apple do to make developing for the Mac easier or better going forward?
I guess they would say they are already doing it with Swift/SwiftUI. And maybe they are - maybe in a few more years I'll get to find out! I'd also like to see them overhaul the security settings so that they worked reliably. Things like App Translocation being invisibly turned off because you move an Application in the Finder is really not a helpful interface.
How else do you automate?
I automate anything I can. I have a large number of commands run as Launch Daemons, using Lingon X to help me manage them. They handle things like backups, checking my systems (often interacting with healthchecks.io <http://healthchecks.io/> to report issues), posting automated messages, sending out Getting Started tips to new customers, and processing sales. I also write endless Perl scripts to help semi-automate things like creating builds or reconciling bank statements. I mentioned there are a lot of actions, I have a script which duplicates an existing action to a new action, adjusting the name in all the related files.
How do you relax or take a break?
I like to do Escape Rooms, listen to audio books, walk or lift weights, or (too often) veg in front of the TV while playing sone inane iPhone game. I enjoy building things, often with an electronic component, but I don't make the time to do that very often. As my kids age out of school and head off on their own adventures, I hope to get back to doing more traveling with my wife.
Whose work inspires or motivates you, or that you admire?
I think the two programmers that most inspired me are John Norstad and Rich Siegel. John almost single handedly wiped out viruses on the Mac for the entire 90s, and his program’s elegance in performing tasks modelessly was something I always liked and try to emulate. He also had a focus on keeping complexity down, minimising preferences and other things that add cognitive load to the user and maintenance load to the developer. I'm not sure how well I've managed to emulate that. And Rich Siegel, author of BBEdit, has been an idol of mine since he was putting out updates of THINK Pascal, and I continue to use BBEdit pretty much every day.
Anything else you'd like to add?
Just to encourage people to automate the things they can. People often think automation is about speeding things up, and it is, but it is also about consistency - something you automate will produce an identical result every time, where doing it manually will introduce little changes that may or may not come back to bite you later. You don’t have to use Keyboard Maestro (you should, of course), but you should be looking at the things you do repetitively, or things which are irritating, or tedious, and looking for ways you can automate them. The joy that comes from hitting a key and then sitting back and watching your computer perform a serious of tedious steps through some web site, between some applications, and finishing up with a nicely polished, always perfect, result is hard to overstate.