Computers go to sleep as a way to save energy and prevent unnecessary wear on your hardware. On macOS you can fine-tune this feature in System Preferences > Energy Saver.
But there are times when you might want to prevent your Mac from sleeping, for example until a certain task is completed. And changing the settings back and forth can be annoying.
There’s an easier way…
When it comes to preventing your Mac from going to sleep, most macOS users immediately think of an app. Of course, there’s always an app. There is Caffeine which is a free popular options, but there’s also paid options.
What some ( most? ) macOS users seem to don’t know, is that this functionality is built-in into macOS for the last six years or so. And it’s a command line program called caffeinate. What were the chances right?
Being a command line tool, depeding on how comfortable you are with using the terminal and/or understanding the OS’ filesystem, you might not use it at it’s full potential. But even a complete noob can take advantage of caffeinate , and completely eliminate the need to install yet another app which can also be a potential security risk.
NOTE: I’m not saying that any of the third party apps that prevent your Mac from going to sleep have security flaws, all I’m saying is that ANY app you install can be yet another security risk.
So let’s see how to use caffeinate…
To prevent your Mac from going to sleep using the built-in caffeinate app, all you have to do is to open up the Terminal, type
caffeinate and press enter.
If you run the command by itself, you will prevent your Mac from going to sleep as long as the command is active.
To stop it you will need to kill the process with
c while inside the Terminal.
You can also set a sleep timer to caffeinate. For example, if you want to prevent your Mac from going to sleep for an hour you will type in
caffeinate -t 3600. Change the timer ( in this example is 3600 ) to whatever you need. Time is expressed in seconds.
You can also target a specific application. For example, you might want to prevent your Mac from going to sleep while you export a video. All you have to do is type
To do this you will have to right click on the app inside the /Applications/ folder, and select Show Package Contents and drag-and-drop the core of the app inside the terminal to get its path ( so you don’t have to type it ). Hint: the core is usually located in
For more fine-tunning, there’s some spcific flags that you can use with caffeinate.
-dwill prevent the display from going to sleep
-iwill prevent the system from idle sleeping
-mwill prevent the disk from going to sleep
-swill prevent the machine from going to sleep when plugged in
-ureplicates a currently active user