Computers sleep as a way to save energy and prevent unnecessary wear on your machine's hardware. Yet there are times you may want to stop your Mac from sleeping such as when you’re watching a movie, cloning a large repository from GitHub, or need to let a large download finish from your favorite website.
When in these situations, it can be inconvenient to look through System Preferences > Energy Saver until you find the settings needed and then you must remember to re-enable your original settings when you are done. With OS X 10.8, Mountain Lion, we are able to stop our Macs from sleeping for a period of time from our command line with the
caffeinate command. Let’s take a look at how to use this command, and some alternatives for older machines.
Caffeinate and How to Use It
caffeinate command is used to prevent a Mac from going to sleep. The simplest way to use this command is to run the following command in the terminal.
When run, the cursor will move down to a blank line where it will stay until you tell the command to stop running or close the terminal. While running,
caffeinate will prevent your Mac from sleeping. To stop the process from running, you can press Ctrl+C which will instantly end the process, and return you to the command prompt.
For some situations, such as while watching a movie, this may be fine. Other times, you may prefer to set the duration you would like to prevent the Mac from sleeping. Luckily, Apple has made this rather easy to accomplish by using the
-t option to your command, followed by the time in seconds. For example, if you wanted to prevent your Mac from sleeping for 5 hours, you would run the following command:
caffeinate -t 18000
caffeinate command can also be linked to other commands, such as cloning a git repository, by linking
caffeinate to a specific command. This can be done in the following way:
caffeinate [command_you_want_to_link] -arguments
Tip: The brackets around the command (
[command_you_want_to_link]) are there for demonstation, but would not be used around a normal command such as
Using Caffeinate’s Options
Apple understands that each person using this command may have different needs and has provided a number of different options to let users decide what is needed in their situation. These options include:
-d— Prevent the display from sleeping.
-i— Prevent the system from idle sleeping.
-s— Prevent the system from sleeping. This is valid only when system is running on AC power.
-u— Declare that a user is active. If the display is off, this option turns the display on and prevents the display from going into idle sleep.
-t— Specifies the timeout value in seconds for which the command is valid.
To learn more about
caffeinate and other ways to use the command, visit the Mac Developer Library entry on caffeinate.
Alternatives to the Command Line
Older versions of OS X, unfortunately, do not have the ability to use this command, and the convenience of an application can be difficult to beat. Luckily, developers have listened and provided a number of convenient and compatible options. Each of these includes different features, ranging from simple time settings to more advanced facical detection via the iSight camera, so I encourage you to look through them to find what best fits your needs. These include, but aren’t limited to:
- Caffeine on the Mac App Store by Lighthead Software — Free
- InsomniaX by semaja2 — Free
- Should I Sleep on the Mac App Store by Marcelo Leite — $1.99
- SleepLess by ALXsoft — $9.50
- SmartSleep by Jinx — $3.99
In this Quick Tip we briefly covered some reasons you may want to prevent your Mac from sleeping, how to use the
caffeinate command, and lastly I shared some applications that available to users who may prefer the convenience of an application or may not have Mountain Lion installed on their machine. I hope you’ve enjoyed this quick tip, if you have any questions please let me know in the comments and I’ll do my best to answer them!
Envato Tuts+ tutorials are translated into other languages by our community members—you can be involved too!Translate this post