prevent OS X sleep whilst running specific launchd plist

1.3k Views Asked by At

I have a global launchd plist file that runs a backup script periodically. The script is a pretty simple bash script that sets up some variables and calls duply. However the plist doesn't seem to be preventing the system from going into sleep mode.

Is there a way of preventing the mac from going into sleep mode whilst this specific launchd plist and associated script are running?

2

There are 2 best solutions below

0
On BEST ANSWER

The solution that seems to be working is

caffeinate -s [utility]

This forces the system to stay awake until the [utility] closes.

-s Create an assertion to prevent the system from sleeping. This assertion is valid only when sys-tem system tem is running on AC power.

The full man page explains more.

https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man8/caffeinate.8.html

5
On

I use the following to prevent my Mac sleeping:

pmset noidle

and then I use Ctrl-C to kill that and allow it to sleep again.