Modern MacBooks are incredibly aggressive about saving battery life. If you step away from your desk for a few minutes, the screen will dim, and shortly after, the computer will go to sleep. Most of the time, this is a great feature. However, if you are downloading a massive 100GB video game, rendering a complex 3D animation, or running a long Python script, the Mac falling asleep will instantly kill the process and ruin hours of work.
You could open System Settings, navigate to the Lock Screen menu, and manually change the “Turn display off on battery” slider to “Never,” but then you have to remember to change it back later, or you risk draining your battery overnight.
Instead, macOS has a brilliant, hidden command-line tool built right into the operating system specifically designed to temporarily prevent sleep. It is appropriately named caffeinate.
This guide explains how to use the caffeinate command to keep your Mac awake.
Step 1: Open the Terminal
Because caffeinate is a developer tool, it does not have a graphical interface. You must run it from the command line.
- Press Command (⌘) + Spacebar to open Spotlight Search.
- Type Terminal and press Return.
- A small window with a command prompt will appear.
Step 2: Run the Basic Caffeinate Command
To keep your Mac awake indefinitely, simply type the following command into the Terminal and press Return:
caffeinate
The command prompt will drop down a line and appear to just sit there doing nothing. Do not close the window. As long as that Terminal window remains open and running, your Mac will absolutely refuse to go to sleep, regardless of what your System Settings say. It will stay awake until the battery physically dies.
When your large download or rendering task is finally complete, click on the Terminal window and press Control + C on your keyboard. This will instantly terminate the caffeinate process and return your Mac to its normal, power-saving sleep schedule.
Step 3: Add a Timer (Advanced)
If you know your download is going to take exactly two hours, and you want the Mac to stay awake for the download but eventually go to sleep afterward so the screen doesn’t burn in, you can pass a timer argument to the command.
The -t flag allows you to specify a duration in seconds. For example, if you want to keep the Mac awake for exactly one hour (3600 seconds), you would type:
caffeinate -t 3600
The Terminal will count down silently in the background. Once the 3600 seconds have elapsed, the caffeinate process will automatically quit, and the Mac will be allowed to go to sleep based on its standard energy-saving rules.