This isn't a specific macro, per se, but more of a general technique.

What The Hell Are You Doing: Iterating through an Array of Arrays, using each Array to populate a predetermined set of Variables and then run a Macro with that set, before continuing on to the next Array.

###Array of Arrays
This looks somewhat hacky, and it is, but later I will show you how to generate these automatically. The AoA needs to be stored in a Variable. We are going to be iterating through it using a pair of nested For Each Actions, so it needs to be specifically formatted:


Each sub-Array rests on a new Line, while each Item is separated by a comma.

###Design Within Each

There is a For Each (Line) command which one can use to iterate through Carriage Return separated strings:

And to run through a single line of comma separated values, we can use the following macro:

I stole this bit from peternlewis.

As you may have noticed, I'm running the For Each (Substring) action on the Line Variable generated by the For Each(Line) Action; indeed, I have nested the former within the latter:

This will now run through our AoA Item by Item, Line by Line, and display its values. You may be wondering what that "iterator" thing is for. Well:

###Assigning Value

EDIT: Please check out peternlewis's suggestion below, as it solves this section with a much more elegant and coherent method. Though feel free to continue if you enjoy headaches.

For these subsets to be useful, we're going to have to assign them to Variables. Otherwise each value would only be accessible for the brief moment it is stored as the Item variable within the For Each (Substring) Action. In another moment of hackiness, we're going to use a series of nested If Then Actions:

  1. As we enter a new Line, set an Iterator variable to 0.
  2. Within the For Each (Substring) Action, have an If Then action check the value of the Iterator.
  3. If the Iterator is 0, Assign your first Variable to the value of the Item variable.
  4. Add 1 to the value of the Iterator
  5. Under otherwise execute the following actions in the first If Then action, place a new If Then action.
  6. Repeat steps 3 and 4 with the with the new value of the Iterator and your next Variable.
  7. Continue until you descend into complete madness.


Run the Damn Macro

Outside of this black hole of a For Each (Substring) Action and right at the end of your For Each (Line) Action, execute a Macro, written outside of this silly one, which uses the Variables you have assigned above.

###Automagically Assembling an Array of Arrays

Because I'm about to have an Aneursym, here's a somewhat edifying screen grab:

This is assuming you have your Arrays laid out in an Excel document, following the same pattern listed above. It'll at least give you an idea of where to start.


This is a bit complicated. Please chew me out if I've made any appalling grammatical or orthographic violations.

Other than that, ask me if you'd like anything clarified, I'd love to help out.

I'd also really love to see more silly and complicated macros like this one, because Keyboard Maestro is a silly and complicated piece of software that can do amazingly cool things. You don't even want to know what this Array Assignment Macro feeds into.

Ta ta.


This Macro, as well as many of the more powerful Keyboard Maestro Actions, employ Regular Expressions, those convoluted arrangements of ^().[]* shapes that look like bad ASCII art*. If you'd like to know how they work, an excellent tutorial can be found HERE.

*or perhaps an attempted emoticon of the Human Centipede.

1 Like

Thanks for that. That is a great example of the sort of things you can do. I especially like the "Breathe" ending! Particularly because this sort of thing looks complicated, but it is really just one step at a time.

This is a very general solution and could handle all sorts of things, but one alternative for splitting your line into a set of known variables would be the Search Variable action, something like this:

1 Like

Haha, I was afraid I might have made things needlessly complicated. Then again, that was part of why I posted this, hoping to learn something. While I have used that Action before, KM has so many great tools that I sometimes forget the best one for the job— Also, when you start using loops to solve problems it becomes difficult to stop, I blame inertia.

Mine was still fun to construct, but yours is much pithier and would be simpler to expand upon. I’ll make a note in my post for readers to check out your solution for a more concise and readable option.