How to prevent a MacBook from sleeping

A MacBook has three sleep triggers a desktop doesn't: the battery, the charger, and the lid. Each needs its own fix.

Updated · by Sasha Yakovlev, maker of Lidwork

Quick answer

On a MacBook, idle sleep is set separately for battery and charger. To keep it awake on the charger, enable Prevent automatic sleeping on power adapter when the display is off (System Settings → Battery → Options…) or run sudo pmset -c sleep 0. On battery, use caffeinate -i for the duration of a task. With the lid closed and no monitor, only sudo pmset -a disablesleep 1 (undo with 0) or an app that manages it works.

Desktop Macs have one sleep timer. A MacBook has two — one for battery, one for the power adapter — plus the lid, which sleeps the Mac immediately no matter what the timers say. If your MacBook keeps going to sleep, the fix depends on which of the three you're fighting.

Trigger 1: idle sleep on the power adapter

When plugged in, a MacBook still turns off the display after a while and may then sleep. The setting that stops system sleep:

  • System Settings → Battery → Options… → enable Prevent automatic sleeping on power adapter when the display is off.
  • The display timeout itself is in System Settings → Lock Screen → Turn display off on power adapter when inactive.

The Terminal equivalent, if you prefer it:

# see your current values first — write them down
pmset -g custom

# charger (-c): never idle-sleep the system
sudo pmset -c sleep 0

This is persistent. To return to your previous behaviour, set sleep back to the number you noted (in minutes).

Trigger 2: idle sleep on battery

On battery, macOS is deliberately more eager to sleep. You can change it with sudo pmset -b sleep 0, but leaving a MacBook permanently unable to idle-sleep on battery is a good way to find it flat. The better tool is temporary:

# awake while this task runs, normal afterwards
caffeinate -i ./export-video.sh

# or: awake for one hour
caffeinate -i -t 3600

The caffeinate guide explains every flag, and the command builder writes the line for you.

Trigger 3: closing the lid

This is where most advice stops working. Closing the lid without an external display sleeps the MacBook even if caffeinate is running and even with sleep 0. Your options:

  1. Clamshell mode — power, external display and keyboard/mouse connected. Supported by Apple. How clamshell mode works.
  2. sudo pmset -a disablesleep 1 — disables sleep entirely, lid included. You must undo it with sudo pmset -a disablesleep 0; nothing does it for you.
  3. A lid-closed keep-awake app that manages that switch and puts it back automatically.

The lid settings themselves — what macOS lets you configure and what it doesn't — are in MacBook close lid settings explained.

Low battery: the sleep you shouldn't fight

When a MacBook's battery gets critically low, macOS puts it to sleep to protect your work. Nothing on this page overrides that, and you shouldn't want to. If you keep a MacBook awake on battery, choose a stopping point well above empty. In Lidwork, that's the Sleep at battery level menu: 10%, 20% or 30%, and normal sleep returns at that level — even when the lid is closed.

Other things that look like “sleep”

  • The screen locks but the Mac is awake. Lock Screen settings control locking and display-off separately from system sleep. A locked screen doesn't stop downloads or builds.
  • Low Power Mode. It reduces energy use and may dim the screen sooner; it doesn't force system sleep on its own.
  • Network drops during sleep. Wake for network access lets the Mac respond to some network requests while asleep, but your processes still pause. It's not a keep-awake setting.
  • Something else keeps it awake when you don't want it. Run pmset -g assertions to see which apps hold sleep assertions, and pmset -g | grep SleepDisabled to catch a leftover disablesleep.

Before you pack up: a 10-second check

  1. Plugged in, or a battery floor set?
  2. Lid closed? Then caffeinate alone won't do — confirm pmset -g | grep SleepDisabled shows 1, or that your app shows it's active.
  3. Something hot running (export, compile)? Keep the bag open or the Mac out of it.
  4. Back at your desk: turn keep-awake off and check SleepDisabled 0.

Quick reference

GoalCommand or settingPersistent?
Awake on charger, lid openBattery → Options… checkbox, or sudo pmset -c sleep 0Yes
Awake on battery for one taskcaffeinate -i commandNo — ends with the task
Awake on battery, lid open, indefinitelysudo pmset -b sleep 0Yes — restore later
Awake with lid closed, no monitorsudo pmset -a disablesleep 1Yes — undo with 0
Back to normalsudo pmset -a disablesleep 0 and your old sleep values—

If you want to try a reset instead of restoring values one by one, recent macOS versions support sudo pmset restoredefaults; check pmset -g custom afterwards to confirm the result.

FAQ

Why does my MacBook sleep even with caffeinate running?

Because you closed the lid. caffeinate prevents idle sleep; lid-close sleep on a MacBook without an external display is separate and ignores it.

Can I stop my MacBook sleeping on battery only?

Yes: sudo pmset -b sleep 0 disables idle system sleep on battery. It's persistent, so note your old value with pmset -g custom first and restore it later.

Does Low Power Mode make a MacBook sleep sooner?

Low Power Mode reduces energy use and can dim the display sooner, but it doesn't override caffeinate or pmset. If your Mac sleeps unexpectedly, check your Lock Screen display timers first.