Incorrectly repeating/skipping steps in a loop?

I have a Macro that loops through a Keynote file and takes screenshots. Unfortunately, sometimes the script skips the step to advance the slides before the next screenshot and duplicates the screenshot, or -- more rarely -- the images end up out of order. I've tried adding Semaphore Locks and adding pauses to the script, but no change in the buggy behavior. This is a problem because other scripts are depending on the output files having a predictable filename.

Screenshot keynote file.kmmacros (9.7 KB)

Is this a known issue with Keyboard Maestro, with using screencapture via a shell script, or anything else that has a known work around? Any debugging ideas?

I'm running Keyboard Maestro 6.4.8 on a Macbook Pro running 10.9.5.

(FWIW, the whole purpose of the script is to work around the fact that Keynote '09 doesn't have anti-aliasing support when exporting images.)

I highly suspect the issue is that you’re not waiting long enough after the screencapture.

I would recommend putting in longer pauses for testing purposes. Put them in any location that is timing-sensitive, and use ridiculously long pauses - several seconds - just to see if that solves the issue. If it does, then you can cut down the length of the pauses, or even removing them completely, little-by-little, until you start seeing inconsistent results.

1 Like

I just tried increasing the pause before and after the screenshot to 3 seconds and no change. It’s still duplicating and skipping slides at seemingly random times. Any other ideas are appreciated.

You might try using the KM Debugger, and step through each Action until you can identify the problem.

Semaphore Lock would only help you if you had multiple instances of this macro running at the same time, which you presumably don’t. If you could, the the Semaphore Lock should be earlier in the macro, otherwise the first set of images will be stored as 1…N, and the second as N+1…2*N, or alternatively the counter will be being reset to 0 in the middle of your loop (which could be part of you problem I suppose).

I would suggest starting your macro with:

Semaphore Lock “Screenshots”

rather than putting it in the middle. But that probably isn’t the problem because you presumably aren’t selecting from the status menu a second time while it is still running the macro.

The loop will be looping and the Counter will be counting, those things will be happening in lock step.

The screencapture -oc will be synchronous, although I would suggest you’re better off using the Screen Capture action.

But the typed down arrow, that goes in to a queue and Keynote will get around to it when it wants to. That is where you need your pause, to ensure that Keynote has had a chance to process the down arrow before you continue on.

Thank you!