This morning I started a very long running script with:

caffeinate python spam.py

and when I checked in on the computer several hours later, the computer was asleep! I moved the mouse and the script resumed executing normally. I've looked at man caffeinate and it looks like I should actually use:

caffeinate -s python spam.py 


caffeinate -i python spam.py

What do I need to take into account when picking between -s and -i? What's the difference between preventing the system from sleeping altogether and idle sleeping when caffeinate is running for the duration of a utility's execution?

3 Answers 3


-s option is commonly used with laptops (If the lid is closed, the system does to forced sleep). -s only applies when not using a battery - if there is limited power in the battery the system will sleep no matter what.

-i is for idle sleep which happens when the system has not been used for a certain period.

Note you can use both options keep the system perky if required:

caffeinate -is python spam.py

From the Mac developer library, the differences between idle sleep and (forced) sleep are:

  • Forced sleep occurs when the user takes some sort of direct action to cause the machine to sleep. Closing the lid on a laptop or selecting sleep from the Apple menu both cause forced sleep. The system will also induce forced sleep under certain conditions, for example, a thermal emergency or a low battery.

  • Idle sleep occurs when the machine is unused for a specific period of time configured in the Energy Saver System Preferences

  • 1
    I guess that the "Turn display off after" setting in the Energy Saver System Preferences would be in fact better be called "Idle System Sleep" because it looks like it breaks my OpenVPN connections (ping-restart timeout). caffeinate -i prevents it. So it doesn't just turn the display off because it has a major side-effect. macOS version is 10.15.6. I never had the problem with 10.14. Sep 3, 2020 at 8:45

Save the following lines in the ~/Library/LaunchAgents folder as a plist file such as caffeinate.plist . It will auto start when you log in. There are options to prevent screen, harddrive from sleeping. Just man caffeinate.

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE plist PUBLIC "-//Apple Computer/DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

I do not know much about the python script you are referring to, but if you want your your computer not to go into sleep mode, there is a handy-dandy application called Caffeine that does that for you.

  • That is just running the caffinate command Aug 30, 2017 at 1:02

You must log in to answer this question.

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