On my old Mac, I was using KM to run a macro at 01:30. Sleep mode never worked reliably on that Mac, so there wasn't a problem.
I've got a new Mac now, and sleep mode works reliably again. I had expected KM to wake the Mac to run the macro, then sleep it again afterwards, but it doesn't seem to — the macro doesn't get run at all.
I don't want the macro to run on wake, as it does stuff on servers that needs to be done in the middle of the night when nobody is using them.
Is there a way to get KM to wake the Mac for scheduled macros, and sleep it again afterwards (preferably without having to end each macro with Put Computer to Sleep, as I'd only want it to do that if it was asleep when the macro was triggered…)
I think the simplest solution is to go into Mac System Preferences/Energy Saver and schedule the Mac to wake up a minute before the Macro's scheduled run time. This image is from macOS 12.3.1 so it will look different on a different version of macOS but works the same way.
I don't think you'll need to schedule a "go back to sleep" as that will just happen anyway when the computer is idle.
Thanks — the problem with that is that there is only one time you can set, and I have various jobs that need to run at various times.
I was hoping that KM would support Power Nap so it could register a time to wake without my having to do it myself — but it appears there isn't even an option for enabling Power Nap in the Energy Saver preferences on the Mac Studio, so that wouldn't help.
I may have to just disable sleep altogether and just sleep the displays. I might stand a better chance of having my network mounts still connected that way, too…
Thanks, but the article you've posted isn't a solution to my original question, which was "how to get KM to automatically wake for a scheduled macro, without having to configure it myself?" (Admittedly, it could have been phrased slightly more clearly )
The Wiki documents that, if the Mac is asleep when a timed macro is triggered, the macro will not run, but I believe that's important enough that it should appear on screen in the app when a timed trigger is selected. It's a huge limitation that makes KM very expensive to run, as I can no longer allow my Mac to sleep.
Noted, but I disagree that it is a huge limitation worthy of inclusion in the display.
With the screen slept, the Mac not sleeping is unlikely to use a substantial amount of energy while doing not much. Modern Macs are pretty energy efficient. Personally, my Mac has had sleep disabled for decades to allow it to backup or perform tasks at night.
But in any event, all triggers have various limitations and they cannot all be covered directly in the UI without adding a lot of clutter. Keyboard Maestro is not running when the Mac is asleep, so no triggers will operate. This applies to all triggers, not just time based ones. Network changes, Idle triggers, periodic triggers, cron triggers, USB Device Key triggers, none of them will work if the Mac is asleep, or if the Mac is turned off. And even if it is not asleep, most UI actions cannot work while the Mac is screen locked, screen saving or screen sleeping.
There are no current plans to have Keyboard Maestro automatically wake from sleep to perform macros, because that could easily be more of an issue than not doing that. If the Mac was running on battery then waking from sleep to perform an actions periodically could easily drain the battery.
Fair enough on the energy efficiency — I've just moved from a 2010 Mac Pro with twin Xeons (definitely not energy efficient!) to a Mac Studio, so I guess I still need to get used to that.
It would be nice if there could be an off-by-default option to allow automatic wake from sleep, though — there are still some of us who use desktop systems and who only need to care about batteries when the UPS kicks in
But for now, I think I'll just sleep the screens instead.
Hi @Unikitty. I have an old headless Mac mini that I wake at 2:00, 3:00, and 4:00 a.m. to do some routine tasks using Keyboard Maestro. I stripped out the tasks and created this template that you might want to try.
Cron Trigger—TEMPLATE
PURPOSE
The macro template includes actions that will run when:
This cron entry matches the current time, OR
any other configured trigger is detected (e.g., ⌃⌥F2).
In the former case, the Mac will be put the Mac to sleep unless another instance of this macro is started before this macro completes.
SCHEDULING A MAC TO WAKE
System Preferences > Energy Saver (or Battery) > Schedule > Start up or wake can be used to schedule only one startup time per day. If more times are needed, the command pmset can be used in combination with cron. Since pmset must be run as root to modify settings, the crontab command should be used as follows: sudo crontab
For example, if this template is copied to create macros that trigger 2:00, 3:00, and 4:00 a.m., the root contab file should be set as follows:
• Keyboard Maestro 10.0.2
• Monterey, v12.3.1/MacBookPro16,1
• Mojave 10.14.16/Macmini6,2
• High Sierra 10.13.6/iMac11,1445
VERSION HISTORY
1.0 - Initial version
DOWNLOAD Macro File: Cron Trigger—TEMPLATE.kmmacros (24 KB) Note: This macro was uploaded in a DISABLED state. It must be ENABLED before it can be run. If it does not trigger, the macro group might also need to be ENABLED.