I have a few macros that run at specific times when certain apps are open. (e.g. file Mail messages automatically, or update Evernote collections). If that app doesn’t happen to be open at the scheduled time, it simply skips the run and has to pick up at the next time… potentially delaying the execution of the macro for days.
Is there a way to set those macros (or any scheduled macro, for that matter) to automatically “catch up” on missed executions?
Keyboard Maestro does not have any in-built “catch this macro up if it missed triggering” facilities. If the Mac is asleep (or for whatever other reason) and your macro does not run, then Keyboard Maestro wont trigger it later.
In part this is because it is relatively complex to explain to Keyboard Maestro exactly under what condition you want to “catch up”.
However, Keyboard Maestro provides a whole bunch of tools to help you catch. There are two ways to do this:
Trigger the macro in a bunch of ways, but ensure it only runs at most once per day (or whatever is desired).
Trigger the macro in a specific way, and trigger a catch up macro some other ways and execute the first macro if it has not run sufficiently recently.
So the first form might look like this:
Trigger: Wake
Trigger: Every hour
Trigger: On app activation
If variable "Day This Macro Last Ran" is empty or if calculation "DAY() != Day This Macro Last Ran" Then
Set variable "Day This Macro Last Ran" to calculation "DAY()"
Do stuff
The second form might look like:
Macro "Do Stuff"
Trigger: At 8:00pm
Set Variable "Time This Macro Last Ran" to calculation "NOW()"
Do stuff
Macro "Catchup"
Trigger: At Wake
If calculation HOUR() > 20 or calculation "NOW() - Time This Macro Last Ran > 86400"
Execute Macro "Do Stuff"
Depending on your exact requirements, you would adjust the calculations.
And the variants involved in this give you an idea of why Keyboard Maestro makes no attempt to solve this with some sort of “catchup” checkbox - your definition of catchup will be quite complex/problem-specific when you actually think about under what circumstances you want the macro to run.
I can definitely see how having configurability in the delays would be useful. I was just hoping I wouldn’t have to resort to making yet more variables. (I have dozens by now, a lot of which are probably useless anyhow, but tricky to track down and purge – maybe I need a macro to do that.)
If you did want to make an interface to control “catching up” on executions, you could take a page from Chronosync’s configuration and have an additional condition of “Run no more than once every X hours/days/weeks/months.” This could catch a lot of these cases, and folks could always build it by hand if they had a mind to.
On the manual side, unless I’m missing something there doesn’t seem to be a function to get the week of the year. This was easily worked around by a shell script action of date +'%W' writing the week number out to a variable. But a small gap in the time functions that might be useful to fill in.
The text token %ICUDateTime%YYYY-ww% will return the year of the week of the year and the week of the week of the year (people get a real surprise when they accidentally use a capital Y in their dates!)