☾ SleepToggle · lid-closed sleep, explained

How to keep a MacBook awake with the lid closed

The short answer: run sudo pmset -a disablesleep 1 in Terminal. Your MacBook then stays awake with the lid closed, even on battery, with nothing plugged in — the one thing caffeinate, Amphetamine and the other keep-awake apps can't do. Run sudo pmset -a disablesleep 0 to go back to normal, or use SleepToggle, a free menu bar button for exactly this.

The rest of this page explains why the usual apps fail here, and what to watch out for.

Why caffeinate and Amphetamine don't survive a closed lid

macOS has two different kinds of sleep. Idle sleep happens when the machine has been unused for a while — this is what caffeinate, Amphetamine, KeepingYouAwake and the other menu bar apps prevent, using what macOS calls power assertions. Forced sleep happens when you close the lid. Power assertions don't apply to forced sleep, so closing the lid puts the Mac to sleep no matter how many keep-awake apps are running.

That's not a bug in those apps — it's the mechanism they use. Keeping a closed MacBook awake needs one of two other things.

Option 1: clamshell mode

Apple's supported path. A closed MacBook stays awake if all three are true: it's connected to power, an external display is attached, and an external keyboard or mouse is connected. Good for desk setups; useless if you just want to close the laptop and let a download, build or server keep running.

Option 2: pmset disablesleep — the system's master switch

macOS ships a power-management setting that disables system sleep entirely, including lid-close sleep, on battery, with nothing plugged in:

sudo pmset -a disablesleep 1   # sleep off — stays awake, lid open or closed
sudo pmset -a disablesleep 0   # back to normal

This is the same switch some server and kiosk setups use. Three things to know:

The display still sleeps normally — only system sleep is disabled.

A button for it

SleepToggle is a free menu bar app that toggles exactly this setting: ☾ means normal sleep, ☕ means staying awake. One click each way, and the icon always shows the current state — which matters, because the setting persisting across reboots is exactly the kind of thing you forget. It's about 100 lines of Swift you can read before installing, compiled locally on your own Mac.

curl -fsSL https://sleep.138.dk/install.sh | bash

Prefer doing it by hand? The two pmset commands above are the whole trick — SleepToggle just puts them a click away. See how it works or how it compares to Amphetamine & co.