Keep a MacBook awake with the lid closed, and when not to
· 6 min read
A MacBook goes to sleep when you close the lid, and macOS offers exactly one supported way around it: connect an external display, an external keyboard or mouse, and power, and the Mac keeps running on the external screen. If you want it awake with the lid shut and nothing attached, that takes a Terminal command that disables sleep entirely, and it is worth understanding what that does to a laptop before you run it.
What macOS does on its own
Apple calls the supported setup closed-display mode, and most people call it clamshell mode. The conditions are:
- The power adapter is connected.
- An external display is connected, by cable or through a dock.
- An external keyboard and mouse or trackpad are connected, USB or Bluetooth.
Close the lid and the built-in display switches off, the external one becomes the only screen, and the Mac carries on. Open the lid and the built-in screen rejoins. If Bluetooth peripherals do not wake the closed Mac, check System Settings, Bluetooth, and make sure the keyboard or mouse is actually paired rather than connected through a receiver the Mac cannot see.
For a laptop that lives on a desk with a monitor, this is the answer, and no setting needs changing.
Stopping it from dozing off while plugged in
A related complaint is the Mac that is plugged in with the lid open, doing something long, and sleeps anyway because nobody touched it. That is idle sleep, not lid sleep, and there is a switch for it.
Look in System Settings, Battery, then Options (on some versions the same switch lives under Displays, Advanced). Turn on “Prevent automatic sleeping on power adapter when the display is off”. The display still turns off on its usual schedule; the Mac behind it keeps working. On battery there is no equivalent, because a laptop that never sleeps on battery is a flat laptop.
The Terminal alternative is caffeinate. Run caffeinate -i in a Terminal window and the Mac will not idle-sleep until you press Control-C in that window. Add a timer so it cannot be forgotten: caffeinate -i -t 3600 holds it for an hour. Put a command after it, for example caffeinate -i rsync ..., and sleep is prevented only for as long as that command runs, which is the cleanest form.
None of this changes what the lid does. Close it with only caffeinate running and the Mac sleeps regardless.
Keeping it awake with the lid closed and nothing attached
Sometimes the display and keyboard are not part of the picture: a MacBook serving files on a shelf, a long download overnight in a drawer, a build that has to finish while you carry the machine somewhere. For that macOS has no switch, only a power management flag:
sudo pmset -a disablesleep 1
Enter your password. From then on the Mac does not sleep, lid open or closed, on power or on battery. To put things back:
sudo pmset -a disablesleep 0
Check the current state with pmset -g; look for a line reading SleepDisabled 1. The flag survives restarts, so it is not something to set and forget.
Mainspring exposes the same flag as a power-up called “never sleep with lid closed”, with a “caffeinate on a timer” power-up beside it for the temporary case. It is one of the reasons the app is sold directly rather than through the Mac App Store: the sandbox does not allow a store app to touch power management. The useful part is the revert. Each power-up records the previous state before it changes anything, so undoing this one is a click rather than remembering a pmset line at 11pm.
When not to
Lid-closed running is safe on a desk. It is a bad idea in the following places, and the reason is heat.
In a bag. A closed MacBook is still a running computer. Fan-cooled models push warm air out around the hinge; fanless models shed heat through the case. A padded sleeve does the opposite of both. Macs will throttle and eventually shut down to protect themselves, but a laptop that arrives hot and at 12 percent battery has not had a good journey either.
On a bed, a sofa, or anything soft. Same problem with a slower onset.
Stacked under something. Papers on top of a closed laptop are fine while it sleeps and less fine while it renders video.
When you rely on it locking. With sleep disabled, closing the lid does not lock the screen. Anyone who opens it is where you left off. If the Mac holds anything you would not leave on a café table, set the lock properly first; Require a password immediately after a Mac sleeps covers it, and Control-Command-Q locks the screen on demand before you close the lid.
On battery for anything long. Sleep is how a laptop keeps its charge overnight. Disabled sleep on battery is a countdown.
The general rule: use closed-display mode with a monitor, use caffeinate with a timer or a command for jobs, and reach for disablesleep only when the Mac is on a hard surface, plugged in, and you have a reason to close the lid at all.
The dimmed screen versus real sleep
Two things look similar and are not. The display turning off is a display setting: System Settings, Lock Screen, “Turn display off on power adapter when inactive”. The Mac sleeping is a separate step that follows some time later. Every method in this guide is about the second one. If all you want is the screen to stay lit during a presentation, Switch a Mac between work, focus and presentation setups covers that with caffeinate -d, which holds the display rather than the system.
Questions
Does closed-display mode work on battery? Apple’s documented requirement includes the power adapter. Some configurations stay awake for a while without it, but treat that as luck rather than a feature, and expect the Mac to sleep when you close the lid if it is unplugged.
Will disablesleep stop the Mac sleeping when the battery is critically low?
Do not count on it. macOS still protects the hardware, and a Mac that shuts down at zero percent takes any unsaved work with it. Plug in.
Can I close the lid mid-download and have it resume later?
If the Mac sleeps, most downloads pause and resume when it wakes; some time out. The reliable approach for a long transfer is caffeinate -i in front of the command, lid open, or closed-display mode on a desk.
Is there a way to keep it awake for exactly the length of a meeting?
caffeinate -i -t 5400 gives ninety minutes and then lets the Mac go back to normal on its own. Mainspring’s timer power-up does the same from the menu bar.