The caffeinate command: keep a Mac awake from Terminal
How to use macOS's built-in caffeinate command to stop sleep for a set time, while a command runs, or until an app quits.
caffeinate ships with every Mac. It stops the Mac sleeping for as long as it runs.
The basics
Open Terminal and type:
caffeinate -d
The Mac and display stay awake until you press ⌃C.
The useful flags
| Flag | Prevents |
|---|---|
-d |
The display from sleeping |
-i |
The system from idle sleeping |
-m |
The disk from idle sleeping |
-s |
System sleep (only on AC power) |
-u |
Declares the user active (wakes the display) |
-t 3600 |
Runs for 3600 seconds, then stops |
-w 1234 |
Runs until process 1234 exits |
Recipes
Keep awake for two hours:
caffeinate -d -t 7200
Keep awake while a command runs:
caffeinate -i rsync -a ~/Photos /Volumes/Backup
Keep awake until an app quits (find its process ID first):
caffeinate -i -w $(pgrep -x "Final Cut Pro")
Without Terminal
If you’d rather click than type, Vigil does the same from the menu bar: 15 minutes, 1 hour, 3 hours, forever, or until an app quits, with the time left counting down. Free alternatives: Amphetamine and KeepingYouAwake. Compare: best keep-awake apps.
Vigil, live in your browser
This is the real interface. Click around. If it fits, it's yours for $4.99 once, with free updates.