How to keep your Mac awake (without changing your settings)
Stop your Mac sleeping during long downloads or builds with caffeinate, a menu bar toggle or System Settings, and see what's keeping it awake.
Your Mac goes to sleep when it decides nobody is using it. That's great for battery life, and frustrating when you're halfway through a 40 GB download, a long build, a large file copy or a video render.
There are three good ways to keep a Mac awake for a while. Each one fits a different situation.
The short answer
| If you want to… | Use |
|---|---|
| Keep it awake while one command runs | caffeinate -i your-command |
| Keep it awake for a set time | caffeinate -i -t 3600 |
| Switch it on and off without Terminal | A menu bar toggle such as StayAwake |
| Keep a desktop Mac from ever sleeping | System Settings (a permanent change) |
Option 1: caffeinate, built into macOS
Every Mac ships with caffeinate, a command-line tool that holds a power assertion for as long as it runs. A power assertion is a request that tells macOS not to sleep. Open Terminal and type:
caffeinateWith no options, it prevents idle sleep until you press Control-C. These are the flags worth knowing:
| Flag | What it does |
|---|---|
-i | Prevents idle system sleep (the default when you give no flag) |
-d | Prevents the display from sleeping |
-m | Prevents the disk from idle sleeping |
-s | Prevents system sleep, but only while on AC power |
-u | Declares that the user is active and wakes the display (5-second default timeout) |
-t 600 | Releases the assertion after 600 seconds |
-w 1234 | Holds the assertion until process 1234 exits |
The most useful trick is putting a command after it. caffeinate runs that command and keeps the Mac awake only until it finishes:
caffeinate -i rsync -a ~/Projects /Volumes/Backup/
caffeinate -i -t 7200 # two hours, then back to normal
caffeinate -d -i # keep the screen on too, for example for a dashboardThe downside: you need a Terminal window open, and it's easy to forget one running in a background tab.
Option 2: a menu bar toggle
If you'd rather click than type, a menu bar app puts the same power assertion behind a switch. StayAwake is our free one. Click the moon, tick Prevent Sleep, and the icon gets a slash through it while sleep is on hold. Untick it, or quit the app, and macOS goes back to normal.
Under the hood it asks macOS for exactly what caffeinate -i does: a PreventUserIdleSystemSleep assertion. The display can still dim and turn off on schedule while your download keeps going. It doesn't change any settings and doesn't need an admin password.
Option 3: change System Settings
System Settings has options for when the display turns off, and on many Macs a "Prevent automatic sleeping … when the display is off" switch. Their names and locations vary by Mac model and macOS version, so the quickest way to find them is to search for sleep in System Settings.
This is the right choice for a Mac that should always stay on, like a Mac mini acting as a home server. For a one-off download it's overkill: it's a permanent change you have to remember to undo.
Check what's keeping your Mac awake
Want to confirm that an assertion is active, or find out why your Mac won't go to sleep? Run:
pmset -g assertionsLook for PreventUserIdleSystemSleep in the summary at the top. The list below it shows which process holds each assertion. With StayAwake switched on, you'll see a line like this:
pid 4321(StayAwake): [0x…] 00:05:12 PreventUserIdleSystemSleep named: "StayAwake is enabled by the user."Audio apps, video playback and backups hold assertions too, which is often why a Mac stays awake when you expect it to sleep.
What none of these can stop
caffeinate -i and StayAwake only prevent sleep caused by inactivity. Closing a MacBook's lid, choosing Sleep from the Apple menu, or a critically low battery will still put the Mac to sleep.
Which should you use?
- For scripts or a single long job, use
caffeinate -i your-command. - For switching it on and off during the day, use a menu bar toggle like StayAwake.
- For a Mac that should never sleep, change System Settings.