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:
array1item1,array1item2,array1item3
array2item1,array2item2,array2item3
array3item1,array3item2,array3item3
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:
- As we enter a new Line, set an Iterator variable to 0.
- Within the For Each (Substring) Action, have an If Then action check the value of the Iterator.
- If the Iterator is 0, Assign your first Variable to the value of the Item variable.
- Add 1 to the value of the Iterator
- Under otherwise execute the following actions in the first If Then action, place a new If Then action.
- Repeat steps 3 and 4 with the with the new value of the Iterator and your next Variable.
- Continue until you descend into complete madness.
BEWARE OF SCREENGRAB:
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.
###Breathe
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.
Resources
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.