3

Is it possible to prevent a Mac from going to sleep immediately when a user chooses "Sleep" from the apple menu?

I'm aware of caffeinate -i as a means of preventing automatic sleep (triggered via powerd after the system sleep time set in the Energy Saver preference pane) however, when a user tells a machine to sleep manually it goes to sleep immediately. This is problematic however if it happens when running things like backups which will either be greatly delayed, or remote backups that can be interrupted and fail (lose the remote connection).

What I'd ideally like to do is change the behaviour of the apple menu "Sleep" command to instead be treated as "turn off display, sleep when ready" or just "turn off display", so that I can use caffeinate -i to block full system sleep until certain processes have finished in all cases.

Is such a thing possible? And to clarify, I'm asking this because it's a system for a family member who just will not stop choosing sleep from the apple menu no matter how times I tell them to just turn off the display and let it go to sleep on its own; so yes, I guess I'm looking for a technical workaround to a problem user. 😂

1 Answer 1

1

Unfortunately for your situation, changing the behaviour of the Finder's Sleep menu item is not possible.

A user's request to sleep is privileged by design in macOS. If a user requests sleep, that will overrule software power assertions by tools like caffeinate.

Only hardware devices can block user requested sleep via their IOKit or DriverKit driver. Even this is designed to be for a limited time. macOS's reason to support delays is to allow data to be written to storage and for physical processes to finish.

A simulated hardware device could also block sleep using the same mechanism.

I have helped Power Manager customers schedule frequent wake events, every ten minutes, to try and avoid user requested sleeps affecting long running processes. The approach works but is not a reliable solution. The scheduling can also be done with pmset.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .