How to Keep a Mac from Sleeping (macOS Settings and Terminal)

macOS has one advantage over Windows here: a keep-awake tool is already installed. It is called caffeinate, it lives in Terminal, it needs no download, and it does exactly one job well.

This guide covers the Settings route, the Terminal route, and what to do on a Mac managed by an employer.

Route 1: System Settings

Apple has reorganised these panels several times, so the exact wording depends on your macOS version. On recent releases:

  1. Open System Settings from the Apple menu.
  2. Go to Lock Screen. This holds "Turn display off on battery when inactive", "Turn display off on power adapter when inactive", and "Require password after screen saver begins or display is turned off".
  3. Set the display-off values to Never for power adapter, and leave a sensible value on battery.
  4. Go to Battery (laptops) or Energy Saver (desktops) and click Options.
  5. Enable Prevent automatic sleeping on power adapter when the display is off if you want background work to continue with the screen dark.

That last option is the one worth understanding. It separates two ideas that people usually conflate: the display sleeping, and the machine sleeping. With it enabled, your Mac can go dark while a download, backup or render continues at full speed - which is usually what you actually wanted.

Route 2: caffeinate in Terminal

Open Terminal (Applications → Utilities, or press Command+Space and type Terminal) and use one of these:

CommandWhat it does
caffeinatePrevents system idle sleep. Display may still turn off.
caffeinate -dPrevents the display sleeping. This is the one most people want.
caffeinate -iPrevents idle sleep of the system.
caffeinate -sPrevents sleep while on AC power.
caffeinate -d -t 7200Keeps the display awake for exactly 7200 seconds (2 hours), then stops.
caffeinate -d -w 4821Stays awake until process ID 4821 exits.
caffeinate -i make buildRuns a command and keeps the Mac awake only until that command finishes.

To stop it, press Ctrl+C in the Terminal window, or just close the window. There is nothing to uninstall and nothing left running afterwards.

The best form is the last one in the table. caffeinate -i ./long-script.sh keeps the machine awake for exactly as long as the job takes and not a second more - no remembering to turn it off, no flat battery in the morning.

Route 3: Hot corners for the opposite problem

While you are in the settings, it is worth knowing about the reverse trap. System Settings → Desktop & Dock → Hot Corners lets you assign screen corners to actions, and one of the defaults on some setups puts the display to sleep when the pointer reaches a corner. If your Mac blanks the moment you flick the mouse to a corner, that is why.

Route 4: Amphetamine and other apps

Amphetamine, from the Mac App Store, is the best-known graphical option. It adds triggers - keep awake while a specific app is running, while a drive is mounted, while the battery is above a threshold - which caffeinate cannot do without scripting. It is free and well maintained.

If caffeinate covers your need, though, there is no reason to install anything. Fewer background utilities is generally the better outcome.

On a managed Mac

If your Mac is enrolled in an MDM system, the sleep and lock settings may be enforced by a configuration profile. You will see options greyed out, and you can confirm it under System Settings → Privacy & Security → Profiles (visible only if profiles are installed).

What still tends to work:

What will not work: fighting the configuration profile. If the password-after-lock delay is set to zero by policy, the screen will lock the moment the display turns off, and preventing display sleep is the only way around it.

Checking what is keeping your Mac awake

The inverse question - why will it not sleep - has a good answer too. In Terminal, run:

pmset -g assertions

This lists every process currently asserting that the system or display must stay awake, with the reason. A video call app, a media player, or a forgotten caffeinate will show up here immediately.

Related: pmset -g shows your current power settings, and pmset -g log | grep -e "Sleep" -e "Wake" gives a history of sleep and wake events with their causes.

Quick reference