Better sorting with Keyboard Maestro Macro Palettes

As a teacher, I comment on a lot of student writing. I usually do this digitally, as my handwriting is so awful as to make doctors weep. And, because students in the same classes tend to be learning the same things at the same time, I often find myself needing to say the same thing over and over, to lots of students in lots of different classes.

Since I need to be able to inject these comments quickly, easily, and repeatedly, I’ve been trying to find a good way to automate them for some time now. In my last attempt, I’ve figured out a pretty good way to do this—solving a long-standing problem I’ve had with Keyboard Maestro in the process.

A couple of quick examples. Some of these are usually marginal comments about small issues:

In college writing, it’s polite to refer to people we don’t know by their last name, rather than their first (so “Tan” rather than “Amy”).

Others are usually longer notes about more significant, essay-level issues:

Sentence Boundaries. We’ll talk about this in class a bit later, but for the moment, here’s a resource online for how to look at this issue. I’d definitely recommend you come work with me in my office on this—it’s a tough thing to figure out, and it’s one that’s really important for academic readers.

Attempt 1: Textexpander

Since I need to drop these in at different times in different places and different formats, I’ve been trying to find a way to integrate them into my workflow that is both unobtrusive and pervasively accessible. At first, these were a series of Textexpander snippets, but the problem with that—at least for me—is that I ended up with a slurry of arcane abbreviations that I could never remember, and so I ultimately forgot I’d set them up. As a result, Textexpander flopped for this purpose pretty quickly.

Attempt 2: Keyboard Maestro Macro Group

Keyboard Maestro seemed a logical next step, especially when I realized that a Macro Group could be set to show a palette in response to a keystroke. So I set up a macro group to show a palette1 in response to ⌘⌥T, and I ended up with something like2 this:

Attempt 2: One Big Keyboard Maestro Macro Group

I sorted and grouped comments in a way that made sense to me at the time, but as things were, I ended up with a couple of commonplaces that didn’t quite fit well into an established category. It was also kind of difficult to sort through—I had a big long list of things, and no easy way to get to them. So the workflow for inserting a commonplace comment was:

  1. ⌘⌥T
  2. Focus on palette
  3. Find desired comment among enormous list
  4. Hand to mouse3
  5. Click desired comment
  6. Hand back to keyboard

This is still faster than typing, for sure, but the two big irritations come in steps 3 and 4—first, finding the comment I want among this sorted, but still quite long, list, and second, having to take my hand away from the keyboard for a task that is, essentially, typing.

This worked for a long time, but when I saw Gabe Weatherhead’s post about using a macro group for dedicated application launchers, I started thinking about this again.

Attempt 3: Dedicated Macro Groups

What I like about Weatherhead’s method is that the revealed palette has hotkeys for each entry, which my method didn’t really allow. (I certainly could have set up individual hotkeys for each entry, but I had way too many for that to be practical.)

What I really needed, though, was a hierarchy of macros—a group of groups, in essence. Since Keyboard Maestro doesn’t allow nesting macro groups in this way, I had to improvise. And because I’m demanding and fiddly, I had to improvise a lot.

3.1: Group Hotkeys

This is the easy way to do things, the way that Keyboard Maestro is most comfortable with. I broke my commonplaces into categorized Macro Groups and gave each macro group a hotkey. (This is identical to Weatherhead’s setup.)

Attempt 3.1: Look at them macro groups.

For MLA Style comments, I can simply hit ⌘^⌥F2 and get a comment palette. Easy.

Attempt 3.1: My MLA Style Comment Palette

Of course, this leaves me with six different non-semantic keyboard shortcuts, with the possibility of expanding more or less infinitely as I add new categories and groupings. (In fact, even as I was typing the keyboard shortcut above, I got it wrong. I could try to sort out more meaningful shortcuts, but that’d still require me getting all that stuff sorted out in my memory, which is unreliable at best.)

What would really be ideal is if I could get a macro palette that would allow me to choose from a number of other palettes. This seems trivial.

Attempt 3.2: A meta-group.

The obvious way to approach this is to set up another macro group intended to launch the palettes for each individual comment group.

My meta-group

The obvious way to set up the macros is like this:

Send a keystroke! What could be easier!

The problem is that this doesn’t work. It seems that KM simulates the desired keystroke, but that the KM engine does not receive that simulated keystroke. In fact, there is no straightforward way I’ve found4 to have a Keyboard Maestro macro show a palette for another macro group for one action—which is exactly what I want, and only what I want. KM can do that, but the only ways it knows how is by a hotkey, the dropdown menu, or the intrusive (to me) global macro palette.

Current solution: Abuse Applescript!

It turns out I was only one step removed from a solution. What I needed was for KM to tell something else to send the keystroke in question to the KM engine. Applescript is the easiest way to do that.

So my current setup:

Macros grouped as above, with arbitrary hotkeys.5

Macros grouped as I desire

Meta-palette keyed to ^;

Meta-palette

Palette launcher macros set up to run an Applescript like the following:6

tell application "System Events" to tell process "Keyboard Maestro Engine"
key code 120 using {command down, control down, option down}
end tell

AppleScript

This ensures that the keystroke actually gets to the KM engine, and so this does work to launch a palette for one action via another palette launched for one action.

The next step

When next I come back to fiddle with this setup, I think I’ll be going back to Textexpander. TE is much better at dealing with text than KM, and so when it comes to something like the above, I could use a rich text snippet rather than a Markdown one when inserting a comment in Pages or Preview.

In that case, I’d still use the KM palette system I’ve set up here to trigger the Textexpander snippets. I’ll leave how to do that as an exercise to the reader.


  1. This actually isn’t true. What I did initially is use a macro group wherein all of the macros had the same hotkey trigger (⌘⌥T), so that hitting that key combo brought up a disambiguation palette. Different implementation, same effect. 

  2. I don’t have a screenshot of my actual setup when things were like this; this is a quick replication of what I had initially. 

  3. vampiric hissing noises 

  4. Although of course that doesn’t mean there isn’t one; if there’s a better way, please let me know. 

  5. Since I won’t be using these hotkeys directly, I picked things that wouldn’t compete with anything else on my system—in this case, ⌘⌥^F[1–6] 

  6. The key code 120 part is the integer version of the key code for, in this case, the F6 key. I got these using the Event Viewer included with KeyRemap4MacBook, but this is necessary because the F keys seem to be a special case. Depending on the key, there may be a simpler way to do it: the System Events dictionary also includes the simpler “keystroke” command that allows the use of simple strings, so an Applescript to trigger my meta-palette could simply use keystroke ";" using control down