caffeinate and pmset command builder

By Matyas Rathonyi. Updated October 15, 2026. Guides

Pick what you want your Mac to do and copy the exact Terminal command. caffeinate holds sleep off while a process runs and needs no sudo; pmset changes saved power settings and needs an administrator password. No caffeinate flag keeps a MacBook awake with the lid closed.

caffeinateTemporary, ends with its process
pmsetSaved until you change it back
-t is seconds3600 is one hour
Lid closed?Only disablesleep or a lid app

Clamshell for Mac keeps the Mac awake with the lid closed while armed. No Terminal, no sudo, no monitor. Free for 7 days, then $9.99 once.

Download free trial

Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Or buy now, $9.99. On your phone? Send the Mac download link to yourself.

Three goals on the left: for 1 hour, while it runs, and on AC only. The first, for 1 hour, is selected and flows into a terminal that types caffeinate -i -t 3600 and a copy button. for 1 hour while it runs on AC only $ caffeinate -i -t 3600 idle sleep held for 1 hour Copy
Pick a goal, get the command.The builder writes the flags, explains each one from the macOS manuals, and warns you when a command keeps working after you walk away.

Mac sleep commands are easy to get almost right. -t takes seconds, not minutes. -s only counts on AC power. pmset disablesleep stays on after you close Terminal. And no caffeinate flag survives closing a MacBook lid. This free builder writes the command for your goal and tells you how it ends. Every flag description below follows man caffeinate and man pmset on macOS 27.

Build your command

The interactive builder needs JavaScript. Every command it can produce is in the table of common commands below.

Which command stops which kind of sleep

A grid of four commands against idle sleep, lid-close sleep and whether the effect is temporary. caffeinate -i blocks idle sleep, not the lid, and is temporary. caffeinate -s blocks sleep only on AC power, not the lid, and is temporary. pmset sleep 0 turns the idle timer off, not the lid, and stays until changed. disablesleep 1 blocks idle and lid sleep and stays until changed. idle lid temporary caffeinate -i caffeinate -s pmset sleep 0 disablesleep 1
Only one row covers the lid, and it is the one that stays on. Blue dots mean yes, red dashes mean no, and the amber dot means AC power only. caffeinate ends with its process; pmset settings stay until you change them, so every pmset command here comes with its undo.

Common commands

The same commands as the builder, for copying by hand. Replace make with your command and 12345 with a process ID.

GoalCommandHow it ends
Stay awake while a command runscaffeinate -i makeWhen make exits
Stay awake until a running process exitscaffeinate -i -w 12345When process 12345 exits
Stay awake for 1 hourcaffeinate -i -t 3600After 3,600 seconds, or Control-C
Keep the display oncaffeinate -d -iControl-C
Prevent sleep on AC power, temporarycaffeinate -sControl-C; applies only while on AC power
Never idle-sleep on the charger, savedsudo pmset -c sleep 0sudo pmset -c sleep 10, or your old value from pmset -g custom
Display never sleeps on the charger, savedsudo pmset -c displaysleep 0sudo pmset -c displaysleep 10, or your old value
Disable all sleep, lid closed toosudo pmset -a disablesleep 1sudo pmset -a disablesleep 0. Closing Terminal does not end it
Stop every caffeinate running as youkillall caffeinateImmediately
Reset every power settingsudo pmset restoredefaultsResets all settings as a group; there is no one-step undo
Show current settingspmset -gRead only. Also pmset -g custom and pmset -g assertions

What every flag means

From man caffeinate. With no flags, caffeinate prevents idle sleep. Given a command, it holds its assertions while that command runs; otherwise until caffeinate itself exits.

From man pmset. Changing a setting needs root, so every setting command starts with sudo. Reading never does.

The manual also notes that changes made through pmset are saved in a persistent preferences file, the same one System Settings uses. That is why a pmset change outlives Terminal, and why the builder always shows an undo.

Before you close the lid on disablesleep. It applies on battery, has no timer and no menu bar indicator, and a running Mac in a bag can heat up and drain its battery. Check pmset -g before you pack the Mac, and see how to undo it if SleepDisabled still reads 1.

When the lid will close

caffeinate alone does not keep a MacBook awake with the lid closed. Its assertions block idle sleep, and closing the lid is a separate sleep path, so the Mac sleeps as soon as the lid shuts, -s included. A pmset sleep timer of 0 has the same limit. The caffeinate lid guide shows why. Your options with the lid closed are Apple's external-display setup, sudo pmset -a disablesleep 1 with its risks, or a lid-closed app.

Clamshell for Mac is the no-Terminal option. It is a menu bar app for Apple Silicon MacBooks on macOS 14 or later that keeps the Mac awake with the lid closed while armed, with no sudo and no external display. It does not use pmset disablesleep and never changes SleepDisabled. While armed it uses the unprivileged IOKit lid sleep-state control plus an idle-sleep assertion, the same kind caffeinate creates. Thermal safety is always on, and the lid change is never saved across a restart.

Clamshell keeps your Mac awake with the lid closed while armed, then returns normal lid sleep when you disarm or quit. Free for 7 days, then $9.99 once for one Mac.

Download free trial

Apple Silicon, macOS 14+. Notarized by Apple. 3.6 MB. Also on Setapp.

Frequently asked questions

Does caffeinate keep a MacBook awake with the lid closed?

No. caffeinate creates assertions that block idle sleep. Closing the lid is a separate sleep path, so the Mac still sleeps when the lid shuts, whichever flags you use. With the lid closed you need an external display, sudo pmset -a disablesleep 1, or a lid-closed app.

How do I keep my Mac awake for 2 hours from Terminal?

Run caffeinate -i -t 7200. The -t value is in seconds, so 7200 is two hours. The assertion is dropped when the timeout ends, or sooner if you press Control-C. Add -d to keep the display on too.

What is the difference between caffeinate -i and caffeinate -s?

Per the caffeinate manual, -i prevents the system from idle sleeping, and -s prevents the system from sleeping but is valid only when the Mac runs on AC power. Neither overrides lid-close sleep on a MacBook.

How do I stop my Mac sleeping only when it is plugged in?

For a temporary hold, run caffeinate -s, which applies only on AC power and ends when you press Control-C. For a saved setting, run sudo pmset -c sleep 0, which sets the charger's system sleep timer to never until you change it back. Note your old value with pmset -g custom first.

How do I undo pmset changes?

Undo the one setting you changed: sudo pmset -a disablesleep 0 for disablesleep, or sudo pmset -c sleep followed by your old number of minutes for a sleep timer. sudo pmset restoredefaults resets every power management setting as a group, so use it only if you want all of them back at their defaults.

Is there a way to keep a closed MacBook awake without Terminal?

Yes. Clamshell for Mac is a menu bar app for Apple Silicon MacBooks on macOS 14 or later that keeps the Mac awake with the lid closed while armed, with no sudo and no external display. It does not use pmset disablesleep, and the lid change is never saved across a restart. It costs $9.99 once after a free 7-day trial.

Related guides

Sources checked October 15, 2026: the caffeinate(8), pmset(1), killall(1) and pgrep(1) manual pages on macOS 27.0, and the non-sudo commands run on an Apple Silicon MacBook. Commands that change settings were not run for this page; their behavior follows the manuals and the guides linked above. The builder runs entirely in your browser and sends nothing anywhere. Clamshell is the publisher of this page.