How Do I prevent my Mac from sleeping while the KM macro is running

Guys, how about this; Macro starts at 3am, Mac is on and ction wake mac is triggered. The system now begins to perform tasks (KM macros with repeat) which can take 4 hours. About 40 minutes later the screen goes off again and KM pauses until the user goes back to the mac and moves the mouse or presses a button on the keyboard for mac to wake up then KM continues to work.

Example of it in action; locate every case with an overdue letter from the client (Applescript execution in KM), then for each case send an email tracing to client tracing it (KM trigger macro at 3am automatically). The mac starts then the screen goes off 30-40 minutes later (after it starts) causing the macro to pause. The macro would normally take 4-6 hours to execute without being interupted. Mac is using High Sierra.

Efficiency features on the Mac are turned off e.g. put mac to sleep when possible etc.
A working macro pauses when the screen sleeps, irrespective of the KM action for the screen to wake up.

I just want to prevent my Mac from sleeping 'while' the KM macro is running.

Any ideas how I can overcome this


Since this is a new question, it would be better asked in a new topic.

You can use the shell tool /usr/bin/caffeinate to tell the Mac not to sleep (either sleep, or display sleep, or whatever).

The tool has to continue running while it holds this state, so you will have to figure out how to keep it running until the process continues. It can run while a subtool runs, so you could write a subtool that kept running until poked by Keyboard Maestro for example. Or you can just keep running it in the background periodically through the process.

How long does the affects of this last?
/usr/bin/caffeinate

As long as the utility keeps running.

Read the man page for more details.

1 Like

Hi Peter, many thanks for bringing this feature to my attention.

Just to confirm the following action would wake up the computer and keep it awake for 16 seconds?

caffeinate -u -t 16

That looks right to me, but I am no expert on the command, and I run with my Mac set to never sleep, so it's not something I ever encounter.