5 Steps for Writing Your Own Macros in Keyboard Maestro

Greetings! Do you have a task that you think should be automated, but don’t know how to go about writing a macro? In this post, I’ll discuss the basics of writing macros and provide some tips to get you started with your own projects.

If you’re just finding this blog, check out my post on Getting Started with Post-Production Automation first.

1. Conceptualize the Macro

Before building a macro, take a moment to define its purpose. Is it to automate a repetitive task? To increase efficiency? To save time? Once you have a clear understanding of your goal, it will be easier to design the macro and ensure that it meets your needs.

Secondly, think about your cost/benefit ratio. How much time it will take to build, troubleshoot, and deploy it, compared to the time you’d spend if you performed the same task manually? Generally, if you’re going to repeat a task more than a few dozen times, it’s worth building out an automation. If you’ll just do it a few times, you’re probably better off biting the bullet and going old-school.

Conceptualize your macro before building it.

Next, consider the scope of your macro. Will it be used for a specific project or can it be used across multiple projects? This will determine the level of detail needed in your design, and inform your organization within Keyboard Maestro.

Finally, design the logic of your macro. Is it going to be a straightforward series of keystrokes, or are you going to be using more complex actions with multiple variables and tokens? Having a clear road-map will speed up the build and prevent errors.

2. Record Your Keystrokes as a First Draft

Keyboard Maestro has a Record function that records all of your mouse clicks and keyboard strokes. It’s a very helpful tool when laying the foundation for a new macro, especially straightforward keystroke series macros.

To use it, create a new macro and press the Record button along the bottom toolbar. After a five-second countdown, Keyboard Maestro will record every keystroke and mouse movement as actions in your macro. A small window will pop up with controls to pause recording, or insert a quarter-second “Pause” action into your macro recipe. (I wish there were a less confusing way to phrase that.)

Once recording starts, your first move should be activating your NLE (or other program) into the MacOS foreground. To do this, click on the NLE icon in the dock instead of clicking on the NLE’s background window.

Your first recorded move should be selecting your NLE in the dock.

Why do it this way? When you click on the dock, Keyboard Maestro records the action as “Activate a Specific Program” – for example, your NLE.

By contrast, if you click directly on the NLE’s window, Keyboard Maestro records the mouse click onscreen, but does not know what or why the mouse is clicking. I call these “dummy mouse clicks,” because they’re not attached to a specific function.

After activating your NLE or other program, continue recording your task’s actions.

While performing your actions, avoid dummy mouse clicks like the plague!! DMCs are highly dependent on your MacOS window arrangement, so moving a window will break the whole macro.

Instead, use keyboard shortcuts as much as possible. Shortcuts are faster, more versatile, and do not care about the MacOS window arrangement.

If you cannot perform an action with a shortcut, use Mac’s menu bar. (This is the bar with File, Edit, View, etc.) Keyboard Maestro will record menu bar clicks as “Select or Show a Menu Item” actions, although you’ll have to clean up extra DMCs after you’re done recording.

To stop recording, press the left Pause button on Keyboard Maestro’s pop-up window. Reactivate Keyboard Maestro, and press the Record button again to stop recording.

3. Clean Up Recording

Once recording is finished, you’ll probably have to clean up extra dummy mouse clicks, false starts, and mistakes. You can delete these actions by highlighting and pressing the delete key.

Also, depending on the complexity of your task, you may have to build in actions that cannot be recorded, like inserting a token or repeat engroups. Check out my previous posts for more information about these advanced actions.

4. Test Your Macro (And Add Plenty of Pauses!)

Test the macro with the Run button or your trigger key. Watch your computer carefully and make sure every step is performed as you expect.

If there are any problems, your first troubleshooting tool should be to add plenty of pause actions into the macro recipe. NLEs like Adobe Premiere and Avid Media Composer are very complex and even the fastest computers usually need a brief pause action between keystrokes to catch up. Otherwise, the program won’t receive some keystrokes and the macro will glitch out.

To troubleshoot specific segments of your macro, you can highlight a group of actions, right-click, and press Try. (You’ll probably have to command-click the initial Activate a Specific Application step, or else Keyboard Maestro will try the macro segment onto itself.)

If needed, you can select some actions to Try them separately from the full macro.

5. Leave Comments for Future Reference

Once your macro is tested and working properly, add some Comment actions into the recipe. Comment actions are text boxes so you can document the steps of your macro for future reference. (They won’t affect the performance of the macro at all.)

Leaving comments is super helpful so you can easily understand your macro’s process. If you’re ever retooling the macro for a new job or task, comments will serve as your guide.

That’s all! Build away. Come back here and leave a comment with any successes or struggles, and I’ll chime in to help however I can.

As always, get on my mailing list to stay in the loop with future guides.

Success! You're on the list.

Leave a Reply

%d bloggers like this: