The Mac caffeinate command: every flag, with examples

Sleepover is the caffeinate command's two most-used flags, -d and -i, as a click on an owl in the menu bar, built for people who want the Mac kept awake without a Terminal window left open. Its lengths are in minutes and hours, and it has its own command for Terminal. This page is also the reference for caffeinate itself: every flag, with examples to copy. Sleepover needs a Bravely Account with the Mac Utility Bundle or Bravely Premium.

  • -d keeps the display on. -i keeps the Mac awake and lets the display sleep, which is also what you get with no flag.
  • -t 900 ends after that many seconds. -w 1234 ends when the program with that ID quits.
  • -s is valid only on AC power. -m keeps the disk from idle sleeping and, by itself, doesn't keep the Mac awake.
  • -u turns the display on, for 5 seconds unless you add -t.

Part of the Mac Utility Bundle. One payment of $19.99 unlocks all five, on every Mac you own.

Four ways to keep a Mac awake, from Terminal or the menu bar

  • Built in

    caffeinate

    Cost
    Included with macOS
    Good for
    Scripts, long commands and anyone already in Terminal. It can tie staying awake to a command, so the Mac sleeps again the moment the work is done.
    Downside
    A Terminal window stays open while it runs, time is counted in seconds, and nothing in the menu bar shows that it's on.

    Apple: the caffeinate manual page (caffeinate.8)

  • Free

    KeepingYouAwake

    Cost
    Free and open source
    Good for
    The same command with a click. Its README calls it a small wrapper around Apple's caffeinate, in the menu bar, for a set duration or for as long as it's switched on.
    Downside
    Its README answers its own question about a closed MacBook with a no: it prevents sleep on desktop Macs and on portables that are open.

    KeepingYouAwake: the project's README

  • Free

    Amphetamine

    Cost
    Free on the Mac App Store
    Good for
    A free menu bar app with far more control: its listing has sessions that run while a chosen app is running or a file is downloading, and a mode for a MacBook with its display closed.
    Downside
    Many settings to learn, and the listing shows its last update as version 5.3.2, on November 10, 2023.

    Amphetamine: its store listing (apps.apple.com)

  • Our app

    Sleepover

    Cost
    Mac Utility Bundle: $19.99 once for five apps
    Good for
    The two flags people use most, -d and -i, as a click on an owl in the menu bar, with lengths in minutes and hours and its own command for Terminal.
    Downside
    It can't run a command for you or wait for a program to quit, and it has nothing like -s, -m or -u.

The same thing from the menu bar, with Sleepover

Sleepover holds the same two power assertions that caffeinate -d and caffeinate -i hold.

  1. Install it and sign in

    Download Sleepover, open the disk image, drag Sleepover into Applications and open it.

    It opens on sign-in. Use a Bravely Account that has the Mac Utility Bundle, or buy the bundle from the window that follows: Get the Mac Utility Bundle opens the checkout in your browser.

  2. Click for -d, or -i

    Click the owl's eyes in the menu bar. That is caffeinate -d: the display and the Mac stay awake until you click again, or for the default length if you've set one in Settings.

    For caffeinate -i, right-click the owl, choose Settings… and turn off Also keep the display awake. From then on the Mac stays awake and the display may sleep.

  3. Minutes, not seconds

    Instead of working out a number for -t, right-click the owl and choose For 15 Minutes, For 30 Minutes, For 1 Hour, For 2 Hours or For 4 Hours. The first line of the menu counts down, as in Awake: 42m left, and Let It Sleep ends a session early.

  4. Use it from Terminal

    Run /Applications/Sleepover.app/Contents/MacOS/Sleepover install-cli once. It puts a sleepover command in /usr/local/bin, so a new Terminal window finds it, and asks for your password once if that folder needs it. Without the password it uses ~/.local/bin and prints the line to add to your PATH.

    Then sleepover on --for 90m keeps the Mac and its display awake for 90 minutes, sleepover on --for 2h --no-display lets the display sleep, sleepover status says what it's doing and how long is left, and sleepover off ends it. Leave --for off and it stays awake until you turn it off. --for takes minutes or hours, up to a week.

What caffeinate does

macOS puts a Mac to sleep after a stretch of inactivity. A program can ask it not to by holding a power assertion, and caffeinate is Apple's small tool for holding one from Terminal. Its manual says it "creates assertions to alter system sleep behavior", and that with no flags it "creates an assertion to prevent idle sleep".

The assertions last exactly as long as caffeinate does. In the manual's words they "persist until caffeinate exits", or, when you give it a command to run, "for the duration of the utility's execution".

It lives at /usr/bin/caffeinate. Nothing needs installing, and it doesn't need sudo.

Examples to copy

Each line follows from the manual's text. The manual notes that the -t limit isn't used when you also give caffeinate a command to run: the command's own length decides.

Flags combine, so caffeinate -di is the same as caffeinate -d -i.

  • caffeinate: awake until you press Control-C in that window. The display may sleep.
  • caffeinate -d: the same, with the display kept on.
  • caffeinate -t 3600: awake for one hour, then it exits. 900 is 15 minutes, 14400 is 4 hours and 28800 is 8 hours.
  • caffeinate -d -t 1800: the display on for 30 minutes.
  • caffeinate -i make: awake until make finishes. This is the manual's own example.
  • caffeinate -i rsync -a ~/Movies /Volumes/Backup/: awake until the copy is done.
  • caffeinate -w 1234: awake until the program whose ID is 1234 quits.
  • caffeinate -u -t 10: turn the display on and hold it for 10 seconds.

Every flag, and what it really holds awake

The quoted words are the manual's. What each assertion does beyond that comes from Apple's notes in the header that defines them, and from caffeinate's source.

One of these surprises people. -m alone doesn't keep the Mac awake, because once you name any flag caffeinate no longer adds the idle one for you, and Apple's notes on the disk assertion say the system may still sleep while it's active. Write caffeinate -i -m when you want both.

  • -d: "prevent the display from sleeping". The Mac stays awake with it: Apple's notes say that while the display is prevented from dimming, the system cannot go into idle sleep.
  • -i: "prevent the system from idle sleeping". The display may still dim and sleep. This is what caffeinate does when you give no flag.
  • -m: "prevent the disk from idle sleeping".
  • -s: "prevent the system from sleeping. This assertion is valid only when system is running on AC power."
  • -u: "declare that user is active". If the display is off it turns on, and it's kept from idle sleep. Without -t, this one lasts 5 seconds.
  • -t seconds: how long the assertion is valid, after which it's dropped.
  • -w pid: wait for the program with that ID to exit, then release. Ignored when you give caffeinate a command to run.
  • a command after the flags: caffeinate starts it and holds the assertion for as long as it runs.

How to stop it, and how to check

Press Control-C in the window where caffeinate is running, or let -t run out. If you've lost the window, killall caffeinate in any Terminal window ends every copy you started.

To see whether one is still running, type pmset -g assertions. Apple's manual for pmset says it "displays a summary of power assertions", and a running caffeinate is in the list under the name "caffeinate command-line tool", next to the kind of sleep it's holding off.

What Sleepover matches, and what it adds

A click on the owl, or sleepover on, holds the assertion behind -d. With the display switch off, or sleepover on --no-display, it holds the one behind -i. The difference is where the control lives: an icon whose eyes are amber while it's on, and a menu that shows the time left.

It has one thing caffeinate has no flag for. Stay awake after restarts, in Settings, keeps the Mac awake with no end, opens Sleepover at login and starts keep-awake again once your account is confirmed. sleepover on --persist does the same from Terminal, and Let It Sleep or sleepover off turns it back off.

For a Mac you reach over SSH, a signed-in Sleepover can make an install token (Settings, Account, Add another Mac). One command on the other Mac then downloads Sleepover, checks that it is signed by Bravely Studios and notarized by Apple, installs it and signs it in with the token. The token signs that Mac into your own account, so keep-awake there still needs the bundle.

What Sleepover doesn't do that caffeinate does

  • It can't wrap a command and stay awake until it finishes, and it can't wait for another program to quit. For a build or a copy that should release the Mac the moment it ends, caffeinate is the better tool.
  • It has no match for -s, -m or -u.
  • Its command talks to the Sleepover app on the same Mac, opening it if it isn't running, and needs the same sign-in and bundle as the menu. Without them, sleepover on says what's missing and opens the sign-in or offer window. It refuses to run with sudo.
  • It doesn't keep a MacBook awake with the lid closed, and it doesn't stop a sleep chosen from the Apple menu or forced by a low battery.
  • It isn't free. caffeinate is.

FAQs

How do I stop caffeinate?

Press Control-C in the Terminal window it's running in. Apple's manual says its assertions last until caffeinate exits, so ending it any other way works too: let the -t limit run out, or run killall caffeinate from another window.

Is the number after -t in seconds or minutes?

Seconds. The manual calls it "the timeout value in seconds", so caffeinate -t 600 is ten minutes and caffeinate -t 7200 is two hours.

Does caffeinate work with a MacBook's lid closed?

Apple's manual doesn't say it does. The assertions behind -i and -d stop idle sleep, and Apple's notes on them say the Mac may still sleep when it's closed. The manual limits -s to AC power and says nothing about a closed MacBook.

Does caffeinate work when a MacBook is unplugged?

The plain command, -i and -d carry no power condition in the manual. -s does, so on a MacBook away from its charger it's -i or -d that does something.

How do I open the man page for caffeinate in Terminal?

Type man caffeinate, scroll with the arrow keys or the space bar, and press q to leave. The page is short: a synopsis, the seven flags and one example.

Sleepover icon

Sleepover

Keep-awake

Part of the Mac Utility Bundle. One payment of $19.99 unlocks all five, on every Mac you own.