How-to Awake
Keep a MacBook awake with the lid closed
When you close the lid of a MacBook, macOS puts the Mac to sleep. A long build, a download or an agent session then stops. This guide shows how to keep the Mac awake with the lid closed, and how to turn normal sleep on again.
The short answer
Run this command in Terminal. Type your password when macOS asks for it.
sudo pmset -a disablesleep 1
To turn normal sleep on again, run:
sudo pmset -a disablesleep 0
Warning: Do not put a closed Mac with sleep off in a bag. The Mac cannot release its heat, and it can become too hot.
Why caffeinate is not sufficient
The caffeinate command stops the Mac from sleep when it is idle. It does not stop the sleep that starts when you close the lid. On battery power, the Mac sleeps when you close the lid, also while caffeinate runs.
Use clamshell mode
macOS has one more way to keep the Mac awake with the lid closed. Connect the Mac to power, to an external display and to a keyboard or a mouse. Then close the lid. The Mac continues on the external display. This works only with all three connected.
Check the sleep state
Run this command to see if sleep is off:
pmset -g | grep SleepDisabled
SleepDisabled 1 means that the Mac does not sleep. SleepDisabled 0 means normal sleep.
The problem with disablesleep
The setting stays on until you turn it off. If you forget it, the Mac does not sleep for days. A Mac on battery power can then run flat, and a hot Mac continues to work.
With Widgetful
Widgetful turns lid-closed awake on and off for you, through a small helper. It always has a way back to normal sleep:
- The guards: low battery or too much heat turns normal sleep on again.
- The timer: awake for one hour means one hour.
- The work modes: stay awake while a process runs, or while your agents work. When the work ends, the Mac sleeps as usual.
- The safe end: when the app quits or stops, or the Mac restarts, normal sleep comes back.