Need two loops with breaks in each

I need to create a macro that includes UNDO and REDO loops (with breaks).

I have about 300 videos which I'm processing in After Effects. Some of them need a filter applied, some don't. But I need to look at each video repeatedly with and without the filter so I can assess. I would normally do this by simply using the native undo and redo functions of After Effects but since I have so many videos to process and my deadline is kinda tight, I'd like to recruit KM to help.

So the sequence would be something like this:

  1. Apply filter

  2. Prompt: Undo? (with 3 buttons as follows):
    [Undo]: Will type the Keystroke ⌘Z and goto Step 3
    [Continue]: Will skip over to Step 4.

  3. Prompt: Redo? (with 3 buttons as follows):
    [Redo]: Will type the Keystroke ⇧⌘Z and goto Step 2
    [Cancel]: Will abort the macro
    [Continue]: Will skip over to Step 4.

  4. Prompt: Close Composition & Save?
    [OK]: will type the Keystroke ⌘W (to close comp window) and ⌘S (to save project)

As you can see I think I got the logic down but I'm not sure how to implement this in KM. And the most difficult thing for me is implementing the sequence breaks and gotos. I'm willing to send someone a $25 Amazon gift card if you can construct this bit for me and save me time.

Happy Holidays!

UPDATE: Unfortunately, I wasn't able to figure this out and had to do the job manually (which took me all day!). I'm leaving this question posted in case someone still wants to answer and share for others. The gift card offer is no longer available.

Thanks for reading!

In cases where you need “goto” like this, you can use a state machine. I described how to do this here:

Basically, you label each of your states, and have a Switch statement that selects what to do, and each entry sets the state variable to whatever the next state is. So perhaps something like:

  • Set State to “1”
  • Switch State of
    • “1”
      • Apply Filter
      • Set State to “2”
    • “2”
      • Prompt “Undo?”
      • if text %PromptButton% is “Undo”
        • ⌘Z
        • Set State to “3”
      • else // Continue
        • Set State to “4”
    • “3”
      • Prompt “Redo?”
      • if text %PromptButton% is “ Redo”
        • ⌘⇧Z
        • Set State to “2”
      • else // Continue
        • Set State to “4”
    • “4”
      • Prompt “Close Composition & Save?”
      • ⌘W
      • ⌘S
      • Set State to “1”

Place the whole thing in a While Forever loop.

If you want Cancel to move to the next video, then you will have to handle all three cases in the prompt, and have another state to break out of the While Forever loop so you can go on to the next loop.

Peter, State Machine (Basics of Computer Science) is a very interesting design pattern. I have used it without ever knowing its formal name, as defined in the above link.

I was going to use your post to spring to a new topic (Macro or Tutorial), but it occurred to me that to be helpful to most users, we need to supply an actual Macro which uses the State Machine. Do you have, or could you easily construct, such a Macro?

Or, if anyone has an existing, working, Macro based on a State Machine pattern that is not too complicated, could you please share it?


I do not have a specific state machine macro. In order to design a good example macro, you really need some sort of problem to solve (such as the OPs I suppose).