Mail Action Macro - Walkthrough

November 28, 2011 by Gabe | [mmd] |

This walkthrough demonstrates how I use Keyboard Maestro to control applications that are not scriptable or have few exposed options.

This example creates some handy macros for quickly filing mail in It’s no where near the power of Mail Act-On but it does provide one of my most used features, which is hotkey triggered filling of Mail messages.

Macro Groups

Before getting into the details of macro creation, I want to describe how I organize my macros. The system is still evolving, but as my collection grows, careful organization and trigger settings become more critical.

I have a system for my macros. I keep related macros together. Not just by function, but by how they are triggered. I use a number of palette triggers that pop-up a palette of actions to select. I do this to reduce the number of keyboard shortcuts that I need to remember. But sometimes I want two palettes that might use the same or similar hotkey[1]. In this case I already have a Markdown palette that uses the opt-cmd-M hotkey and I want a new palette for Mail that also uses opt-cmd-M. Keyboard Maestro will handle this fine by showing an option for one palette or the other, but why waste key presses when I can customize the palette triggers

I don’t use Markdown functions in Mail. I often will compose lengthy emails in NVAlt using Markdown, but with normal Mail use, I just write in plain old text. In this case, I customize the two triggers to only function when appropriate. The Markdown trigger fires in every application except Mail and the Mail trigger on fires in Mail.

Mail Filer Macros

Now I have my two macro groups separated. I need some macros for moving mail items. I typically organize and name my macros according to function and trigger within a single group. I number my macros within a group and assign their hotkey to the matching number. For example, the Mail Filer macro group looks like this:

The number on the right is the macro trigger. Keep in mind that these macros are not available until their group palette is triggered by the opt-cmd-M trigger. That way, there are no conflicts between unrelated macros. When the palette is activated, I get a list and I can select an individual macro by hitting the corresponding number key on my keyboard. I find this setup the most reliable way to keep a lot of macros with only a few key bindings.

The heart of each of these macros is the the Select Menu action. This action provides access to a menu item many levels deep. Here’s an example:

It’s not necessary to manually enter all of the layers in a menu selection. Keyboard Maestro provides a recording functionality that will create the action when selecting a menu. It’s a handy way to build macros but it does record EVERYTHING. After completing the recording I also go back and delete all of the extraneous actions like mouse clicks and application switching.

This was a very simple macro for controlling an application without AppleScript. Keyboard Maestro has the capability to completely simulate human interaction. Anything that I can do with a mouse and keyboard, I can likely script with KM.

  1. I usually pick hotkeys that start with opt-cmd-, where is the first letter of the context. For example opt-cmd-F is my Finder or File palette for manipulating files.