

app file:Ĭaffeinate -i /Applications/Safari.app/Resources/MacOS/Safari Or to have sleep prevention active so long as the Safari web browser is running in the GUI, you’d use the following syntax, note you must specify the full path to the binary within the. You can even run this with your own scripts or commands at another location:Ĭaffeinate -i /private/tmp/./whatisthis.sh

Or perhaps you just want to prevent sleep while an ssh connection is active to a specific server, and you want to send the caffeinate command into the background, then you’d apply an ampersand to the end as well like so: It may already be obvious, but executing the caffeinate command like this will also start the command or process specified in the argument.įor example, if you wanted the Mac to avoid sleeping when the “make” command is active, you’d use the following command syntax:

We’ll run through a few examples but the man page of caffeinate provides a few additional options which may be desirable for other situations too.įor our purposes here to make the sleep prevention dependent on the completion of a specific command or process, you’ll use the -i flag likes so: To accomplish command specific sleep avoidance, we’re going to use a variation of the caffeinate command, which can prevent sleep in a variety of ways.
