Lunille blog

How to keep your Mac awake, with or without the lid closed

The quickest way to keep a Mac awake is a command that's already on it. Open Terminal and run caffeinate -di: the Mac and its display stay awake until you press Control-C. Add -t and a number of seconds to stop on its own, so caffeinate -di -t 3600 lasts an hour.

To keep a Mac awake whenever it's plugged in, there's a setting for that. With the lid closed, the one way Apple documents is closed-display mode, which needs power, an external display, a keyboard and a mouse. Here's each of these in detail, and two free apps that put it in the menu bar. I checked the settings against Apple's support pages for macOS 14 Sonoma through macOS 27.

The Terminal command: caffeinate

caffeinate holds off sleep for as long as it runs. With no options it prevents idle sleep, and the options from its manual page (man caffeinate) choose what it holds off:

OptionWhat it does
-dKeeps the display from sleeping
-iKeeps the Mac from idle sleeping
-sKeeps the Mac from sleeping, only while it's on AC power
-t 3600Stops after that many seconds
-w 1234Stops when the process with that ID quits

A few ways to use them:

caffeinate -di

Keeps the Mac and display awake until you press Control-C in that Terminal window.

caffeinate -di -t 7200

The same for two hours.

caffeinate -i -w 1234

Keeps the Mac awake until the app with process ID 1234 quits, such as a long export or download. Activity Monitor shows each app's PID. You can also put a command after caffeinate -i, and the Mac stays awake while that command runs: the manual page's own example is caffeinate -i make.

If you're not sure why your Mac won't sleep, or whether something is keeping it awake, pmset -g assertions lists what's holding it up and which app asked for it.

If you searched for Caffeine: that was a menu bar app by Lighthead Software. The KeepingYouAwake page below says it hasn't been updated in a while, and the built-in tool with the similar name is caffeinate.

Keep your Mac awake when it's plugged in

On a MacBook (macOS 14 to 27): choose Apple menu › System Settings, click Battery in the sidebar, click Options, then turn on "Prevent automatic sleeping on power adapter when the display is off." The display can then turn off while the Mac itself stays awake on power.

On a desktop Mac: in macOS Sequoia 15, Tahoe 26 and macOS 27, click Energy in the sidebar of System Settings; in macOS Sonoma 14, it's called Energy Saver. Turn on "Prevent automatic sleeping when the display is off."

To keep the display on longer: click Lock Screen in System Settings and choose a longer time next to "Turn display off on battery when inactive" and "Turn display off on power adapter when inactive."

These are the steps on Apple's sleep and wake settings page, which adds that preventing sleep may use more power.

Keep a MacBook awake with the lid closed

Apple documents one way: closed-display mode, where the MacBook keeps running with its lid shut and you use an external display instead. Apple's current troubleshooting article for external displays puts it in one line: with the lid closed, the Mac needs to be connected to power and use an external keyboard and mouse. The older, longer version of Apple's closed-display article lists what you need:

Connect the keyboard and mouse, then power, then the display. Once the desktop shows on the external display, close the lid. Apple's article on dual monitors adds that a MacBook Air or MacBook Pro with M3 can drive two external displays this way, with the lid closed.

Without an external display, Apple doesn't document a way to keep a closed MacBook awake. Neither the caffeinate manual page nor the Battery setting says it does.

Menu bar apps

Amphetamine is free on the Mac App Store, with no in-app purchases. It keeps the Mac awake indefinitely, for a set time or until a set time, and triggers can start a session by themselves. Its listing says it can also keep a MacBook awake while its lid is closed.

KeepingYouAwake is free and open source, and a small wrapper around caffeinate. Click its menu bar icon to keep the Mac awake for a set time or until you turn it off. Its README says it only works on desktop Macs and on MacBooks with the lid open. You can install it with Homebrew: brew install --cask keepingyouawake.

In the notch, with Lunille

I make Lunille, a notch app for the Mac, and Keep Awake is one of the things in its menu. Right-click the notch, choose Keep Awake, then pick 15 minutes, 1 hour, 2 hours, 5 hours or Until Turned Off. The same menu is under Lunille's menu bar icon, and a cup button in the open notch turns it on until you turn it off.

From a script or a shortcut, this line keeps the Mac awake for an hour:

open "lunille://keep-awake?minutes=60"

To end it early, run open "lunille://keep-awake?off".

Like caffeinate, it holds off idle sleep. It doesn't keep a MacBook awake with the lid closed, so for that, closed-display mode above still applies.

If all you need is a few hours of wake time, caffeinate is already on your Mac, and Amphetamine and KeepingYouAwake are free. Lunille makes more sense if you'd use the rest of the notch: a timer and Pomodoro, your music with synced lyrics, your AirPods and their batteries, and your next meeting with a Join button. Luni, the little moon who lives in the notch, keeps you company while the Mac stays up.

Lunille runs on macOS 14 or later, on Apple silicon and Intel, and on Macs without a notch it shows as a small pill at the top of the screen. It's a one-time purchase for up to 3 Macs, with a 14-day free trial that needs no account, at lunille.com.