Skip to content
86% off$349 $48.86code BF2026

Guides

sudo pmset -a disablesleep 1: lid closed, and how to undo it

What sudo pmset -a disablesleep 1 does, how to undo it with disablesleep 0, a wrapper that reverts it after a job, and what Glowmoth's closed-lid mode adds.

TroubleshootingUpdated 6 min read

On this page

You ran sudo pmset -a disablesleep 1 so a MacBook could keep working with the lid closed. Now the Mac won't sleep, or you can't remember whether you ever turned it off.

Why it happens

disablesleep sets a system-wide flag. It is not tied to your Terminal window, your login session or the job you started it for. Closing the window or finishing the work does not reset it. The disablesleep setting is also not described in man pmset, so there is no official page to check its behavior against.

People in Hacker News, MacRumors and GitHub threads describe the same problems:

  • You forget to undo it. The Mac stays awake long after the job finished.
  • The battery drains. A laptop that never sleeps keeps running on battery.
  • The Mac gets hot in a bag. A closed lid in a bag leaves little room for heat to escape, and the bare command watches nothing.
  • The display doesn't always turn off when the lid closes. Some people report this. We haven't verified it ourselves.

The bare command has no timer, no battery limit and no heat limit. Any safety has to come from what you wrap around it.

Check and undo the flag

  1. Open Terminal.
  2. Check the current state. This changes nothing:
bash
pmset -g | grep -i sleepdisabled

SleepDisabled 1 means on. No line, or a 0, means off.

  1. If it is on, turn it off. Enter your password when asked:
bash
sudo pmset -a disablesleep 0
  1. Run the check again and confirm it no longer shows 1.

The -a flag applies to all power sources. If you originally used -b (battery only), still confirm with the check afterwards. After a restart, check rather than assume.

Set it only for the length of a job

If you stay with pmset, tie the flag to a command so it reverts when the command ends. This script runs as root, so the cleanup never waits on a password prompt. A plain sudo login can time out during a long job and leave the cleanup stuck.

Save it as lidjob.sh:

bash
#!/bin/bash
# Run a command with sleep disabled, then restore normal sleep.
# Usage: sudo ./lidjob.sh <command> [args...]
if [ "$(id -u)" -ne 0 ] || [ -z "$SUDO_USER" ]; then
  echo "Run with sudo from your own account." >&2; exit 1
fi
if [ $# -eq 0 ]; then echo "Usage: sudo $0 <command> [args...]" >&2; exit 64; fi

cleanup() { pmset -a disablesleep 0; }
trap cleanup EXIT
trap 'exit 130' INT
trap 'exit 143' TERM HUP

pmset -a disablesleep 1
sudo -u "$SUDO_USER" "$@"

Make it executable once, then run your job through it:

bash
chmod +x lidjob.sh
sudo ./lidjob.sh make build

The command runs as you, not as root. When it finishes, or you press Control-C, the script runs pmset -a disablesleep 0. Because the job goes through sudo, its environment can differ from your normal shell. If a command is not found, give its full path.

What the script cannot catch:

SituationWhat happensWhat to do
kill -9 on the script, or a crashCleanup may never runRun the check command
Crash or forced shutdown mid-jobFlag may surviveCheck after reboot
A job that never endsMac stays awake, no battery or heat limitWatch it, or add a timeout
You had the flag on beforeThe script ends with 0 anywayRe-set it if you need it

Do you need disablesleep at all?

Often not. Apple's documented route is an external display plus accessories. Apple says that with a display and an external keyboard and mouse connected, you can keep working with the lid closed. For a closed laptop with a display, make sure the Mac is connected to power and using an external keyboard and mouse, per Apple's page on dark external displays. Our Clamshell Mode on Mac guide covers that setup. disablesleep is for when you have no external display or no power adapter.

If the Mac still won't sleep after disablesleep 0

If SleepDisabled is off and the Mac stays awake, something else is holding it. Run:

bash
pmset -g assertions

This lists what is blocking sleep and which process owns it. Common holders are a call, a video, a download or a caffeinate command. Mac Won't Sleep? Find What's Keeping It Awake covers the rest.

Checklist before you close the lid

  • pmset -g | grep -i sleepdisabled shows what you expect.
  • The job has a defined end, or you are watching it.
  • The Mac is on a desk or somewhere with airflow, not in a bag.
  • You know how you will revert: the wrapper, or the 0 command.

What Glowmoth's closed-lid mode does differently

We make Glowmoth, a menu bar keep-awake app. Its closed-lid mode runs the same pmset -a disablesleep 1 and 0 pair through a small privileged helper, only while Glowmoth is actually keeping the Mac awake. As of November 2026 Glowmoth is at version 1.0.0, and closed-lid mode has not yet been verified on hardware. Test it on your own Mac before relying on it.

ConcernBare commandWrapper scriptGlowmoth closed-lid mode
Reverts when the job endsNoYes, on exit and Control-CYes, when nothing is keeping the Mac awake
Reverts if the tool crashesNoNoWithin 30 s (a lease renewed every 10 s)
Battery limitNoNoForced on, default floor 20%
Heat limitNoNoForced on, off at "serious" thermal state
Leaves your own disablesleep 1 alonen/an/aYes

It also reverts if Glowmoth quits or crashes, if the helper is removed, at shutdown, and at the next boot via a root marker file. It needs no external display or power adapter, and the battery and heat switches are locked on while it is enabled. If you set disablesleep yourself, Glowmoth shows "Sleep is already turned off with pmset, outside Glowmoth." and leaves it. Clear it with the 0 command above.

Turn it on (MacBooks only, macOS 14 or later):

  1. Right-click the Glowmoth menu bar icon and choose Settings… (⌘,).
  2. Open the Safety tab.
  3. Under Closed Lid, turn on Stay awake with the lid closed.
  4. Approve the helper in System Settings, General, Login Items. Glowmoth opens that pane when approval is pending.
  5. Start a session, for example 1 Hour from the right-click menu.
  6. Close the lid. Glowmoth plays the "Glass" sound and posts "Lid closed, staying awake."

To replace the wrapper script, install the command-line tool under Settings, Advanced, Command Line, then run glowmoth run -- make build. Closed-lid mode applies while the app runs with the switch on. If the app isn't running, run holds its own power assertion and the lid-closed part does not apply. Details are in the closed-lid docs and battery and heat limits. Glowmoth is part of MacSuite, with a 7-day free trial.

If nothing works

For a Mac that won't sleep with the flag off and nothing odd in pmset -g assertions, contact Apple Support. For closed-lid mode, use support and include the caption under the switch.

CaptionFix
"Allow the Glowmoth helper in Login Items to finish."Approve it in Login Items
"macOS couldn't install the helper. Move Glowmoth to Applications and try again."Move the app, retry
"Can't reach the helper. Turn closed-lid mode off and on again."Toggle the switch
"Off below N% battery. Plug in to resume."Plug in
text
Subject: Mac won't sleep / closed-lid mode problem

Mac model and macOS version: 
Output of: pmset -g | grep -i sleepdisabled
Output of: pmset -g assertions
Glowmoth version and the caption under "Stay awake with the lid closed":
What I already tried (sudo pmset -a disablesleep 0, restart):

Common questions

Does disablesleep survive a restart?

Treat it as possible and check. It is a persistent system setting, so run the check command after rebooting rather than assuming it cleared.

Can I set it for battery only?

Yes, -b targets battery power, and -a covers all sources. Undo with the same flag and a 0, then verify.

Is it safe to leave on?

It has no battery or heat limits of its own, so no. Use it for a bounded job, on a desk.

Will Glowmoth clear a flag I set earlier?

No. It only reverts a SleepDisabled it set itself.

Every app.
One purchase.