Goal: Wake my Mac at 1 a.m. and and at 1:01 run a macro to delete Mac Mail emails from specified mailboxes that are older than 10 days by applying some rules. Then sleep the Mac at 1:02 a.m. However, it’s failing when activating Mail.
Sleep/wake is set in the Terminal, which appears to be working, or I assume the macro wouldn't run and give the error message:
Repeating power events:
wakepoweron at 1:00AM every day
sleep at 1:02AM every day
My macro first checks that my ethernet cable is connected, so this doesn’t try to run when I’m traveling:
Then, the macro activates Mail.
But it often (but not always) fails trying to activate Mail (which was usually left running when I put the Mac to sleep for the night.)
Any idea why this action is failing? Or could something else be going on that causes Keyboard Maestro to mis-report the error?
Verify that the macro is triggering by looking in the Engine.log file.
Also, you can use the Log action to log information about the progress and state of the macro which can be helpful for determining what happened in an unattended execution.
However, keep in mind that even if you wake the Mac, if the mac is screen saving screen sleeping or screen locked (the latter seeming to be quite likely at that point), the UI actions will not work.
This is likely the reason you cannot activate Mail, and would not be able to interact with its UI even if you could.
I checked the engine log and did run, right on time. However, there are a number of "Running application query took a while" entries, followed by "GetProcessForPID(87880) failed with -600 for <KBMRunningApplication “Mail”"
So just "waking" the Mac doesn’t bring it to its full capability... I’d need to wake and/or unlock the screen. It seems just activating a running app wouldn’t require the screen to be unlocked, but I have a minimal understanding of what's going on in the background!
My little project is probably not worth the trouble. Perhaps I should set it to run whenever I launch Mail. That would be good enough to keep my subscription mailboxes trimmed.
It probably does - activating it is a UI action, and UI actions can't happen when the Mac is screen sleeping/locked/saving.
Another option is to have it run when your Mac is idle (but before the Mac goes to sleep), and only run once a day. You can do this using the Idle trigger, IDLE function, and DAY function. You might also start your macro with a Display Text Large action to warn you its about to happen, then pause for 10 seconds and then check that the Mac is till idle.
All sorts of options.