Mac How To: Prevent your Mac from sleeping with Terminal

From time to time you may want to prevent your Mac from sleeping without having to go into Settings and turn off Energy Saving mode.

Thankfully, there’s another way to keep your Mac awake. All you need to do is run a single command in Terminal called caffeinate.

Open Terminal (CMD + SPACE and search for Terminal and press Enter) and run the following commands depending on the functionality you need:

Keep awake until disabled:

This one is simple. Your Mac will be kept awake until you either close Terminal (CMD + Q) or cancel the command (CTRL + C).

caffeinate

Keep awake for a set period of time:

This command will keep your Mac awake for a set duration (counted in seconds).

caffeinate -i -t TIME

The following command will keep the Mac awake for 30 minutes:

caffeinate -i -t 1800

Keep awake while an application/process is running:

Note: The PID of an application will change if you quit and re-open it.

This command is arguably the most fun. With this command, you can keep the Mac awake as long as a certain process is running. This could be used alongside certain applications that allow you to quit them when they finish whatever they’re doing.

To find the Process ID of the application in question, open Activity Monitor (CMD + SPACE and search for Activity Monitor and press Enter) and find the application in the list. Look for the applications corresponding PID.

Activity Monitor PID

Once you’ve found the PID, type it in after -w in the command.

caffeinate -i -w PID

The following command will keep the Mac awake as long as Adobe Illustrator (PID 5205) is open.

caffeinate -i -w 5205
Posted in How To, Mac and tagged , , , , , , .

Leave a Reply

Your email address will not be published. Required fields are marked *