macOS is highly optimised to save battery life. By default, if you step away from your computer, the screen will dim, the hard drive will spin down, and the Mac will eventually enter a deep sleep state. This is excellent for battery preservation, but it is disastrous if you are halfway through downloading a massive 50GB file, rendering a 4K video, or running a complex script that requires continuous CPU uptime.
While you can manually dig into the System Settings and change your power preferences to “Never sleep,” doing so is tedious, and you risk forgetting to change it back later. Instead, power users rely on a brilliantly simple, built-in Terminal command called caffeinate.
What is the Caffeinate Command?
The caffeinate utility is a native macOS command-line tool that temporarily overrides your system’s sleep settings. As long as the command is actively running in the Terminal, your Mac acts as if it just drank a cup of coffee: it refuses to go to sleep, regardless of what your System Settings dictate.
How to Keep Your Mac Awake Indefinitely
To use the tool, you must open the macOS Terminal.
- Press Command + Spacebar to open Spotlight Search.
- Type Terminal and press Enter.
- In the terminal window, type the following command and press Enter:
caffeinate
That is it. You will not see a confirmation message; the cursor will simply drop to the next line and blink. As long as that specific Terminal window remains open, your Mac will not go to sleep. The screen may still dim (depending on your settings), but the CPU and network connection will remain fully active.
When your massive download or video render finishes, you can “cancel” the coffee by clicking into the Terminal window and pressing Control + C. This kills the process, and your Mac instantly reverts to its normal, battery-saving sleep schedule.
How to Keep Your Mac Awake for a Specific Duration
Leaving your Mac awake indefinitely overnight because of a 2-hour download is a waste of electricity. Fortunately, you can tell caffeinate exactly how long to keep the machine awake by using the -t (time) flag, followed by a number representing seconds.
For example, to keep your Mac awake for exactly one hour (3,600 seconds), you would type:
caffeinate -t 3600
Press Enter. The Terminal will hold the command active for exactly 3,600 seconds. Once the timer expires, the command automatically terminates, and your Mac is allowed to go to sleep normally.
How to Link Caffeinate to a Specific App
The most powerful feature of the caffeinate command is its ability to watch a specific program. You can instruct your Mac to stay awake only as long as a particular application is running.
First, you need the Process ID (PID) of the application. You can find this by opening the Activity Monitor app and looking at the “PID” column next to the program name (for example, Final Cut Pro might have a PID of 1492).
Once you have the PID, use the -w (wait) flag in the Terminal:
caffeinate -w 1492
Your Mac will now stay fully awake, monitoring Process 1492. The exact second you close Final Cut Pro (or when it finishes rendering and you quit the app), the caffeinate command instantly terminates, allowing the Mac to sleep immediately.