Skip to content
86% off$349 $48.86code BF2026

Guides

Mac Sleeps During a Long-Running Process? Keep It Running

Long R run, build, rsync or backup stops when the Mac sleeps? Hold sleep only while the job runs, with caffeinate or Glowmoth, and fix what still stops it.

GuideUpdated 8 min read

On this page

You left an R script, a build, an rsync copy or a backup running, turned the screen off or walked away, and came back to find it paused. The usual report is "if the screen goes to sleep, all my processes are paused."

Why a long job pauses when the screen turns off

Display sleep and system sleep are different. When only the display sleeps, most processes keep running. When the Mac itself sleeps, the CPU is suspended and every process pauses, including R sessions, rsync and backups. Apple's own sleep settings describe a switch for stopping automatic sleep when the display is off, which tells you the two are separate. See Apple's page on sleep and wake settings at Apple Support.

Causes, most common first:

  1. Idle system sleep. Nothing told macOS the job matters, so it slept after the idle timeout.
  2. Lid closed. A closed laptop sleeps unless it has power and an external display.
  3. Battery or heat. Low battery or a hot Mac can sleep or throttle a laptop, and a tool that holds the Mac awake may pause itself for safety.
  4. The job started while the Mac was asleep. A 1 AM scheduled copy never starts if the Mac is asleep at 1 AM. One forum report from March 2026 describes a SuperDuper copy that ran at 10 AM instead.
  5. The job itself died. A crash, a dropped network connection or a closed Terminal window looks like a pause but is not sleep.

To check which one happened, run this in Terminal. It only reads the power log:

bash
pmset -g log | grep -E "Sleep|Wake" | tail -20

A "Sleep" line soon after you left means full system sleep. No sleep lines means look at the job itself. For the system settings, see our Mac sleep settings guide and why a Mac keeps going to sleep.

Fix 1: wrap the command with caffeinate (built in)

caffeinate ships with macOS. Put it in front of your command:

bash
caffeinate -i Rscript long_job.R

-i prevents idle system sleep while the command runs. The display can still turn off. Nothing on your system changes, so there is nothing to undo.

To cover a process that is already running, find its ID and attach:

bash
pgrep -x rsync
caffeinate -i -w 12345

Replace 12345 with the ID pgrep prints. -w holds the assertion until that process exits. More flags are in our caffeinate command guide.

Two limits:

  • Closing the Terminal window usually ends the job and the caffeinate with it. Run the job inside tmux if it must survive that. tmux keeps the session alive but does not stop the Mac sleeping, so use both.
  • caffeinate has no battery or heat limit, so a multi-day job on battery runs the battery down.

Fix 2: glowmoth run, wait, or the menu

Glowmoth is a menu bar app with a command-line tool. It holds sleep for the length of a command and reports why the Mac is awake.

Install the command-line tool

  1. Right-click the moth icon in the menu bar and choose Settings… (⌘,).
  2. Open the Advanced tab.
  3. Under Command Line, next to Command-line tool, click Install.

This links the tool to ~/.local/bin/glowmoth. If Terminal says glowmoth isn't found, add that folder to your PATH, then open a new window:

bash
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc

To undo, delete that line from ~/.zshrc. Uninstall in the same settings section removes the link.

Run a command

bash
glowmoth run -- Rscript long_job.R

The Mac stays awake while the command runs. glowmoth run returns the command's own exit code, so && and $? in scripts reflect success. Ctrl-C is passed to the command. Exit code 127 means it couldn't start; 128 plus the signal number means a signal killed it.

  • The display is not held by default, so it can sleep. Add --display before the -- to keep the screen on.
  • --label "nightly build" before the -- names the job in the panel.
  • If the Glowmoth app isn't running, run holds its own sleep assertion, so it still works.

Wait for a process that is already running

Don't restart a job that is half done. Hold the Mac until it exits:

bash
glowmoth wait 12345

Find the ID with pgrep -x <name> or in Activity Monitor. --label <text> names it in the panel.

Pick the process from the menu

  1. Right-click (or Control-click) the Glowmoth icon.
  2. Choose Keep Awake While ▸ A Process Runs…
  3. Type a name, PID or part of the command in the search field. The list shows your own processes with CPU % and PID, busiest first.
  4. Select the process and click Keep Awake (or press Return).

The Mac stays awake until that process exits, usually within about a second. The panel shows "<name> is running (PID n)". This is a one-off and isn't saved across a relaunch of Glowmoth. For another user's process, type its PID.

Fix 3: save a rule for tools you run often

For ffmpeg, xcodebuild or rsync, save the name once:

  1. Open Settings… ▸ Automation.
  2. In Processes, type the executable name, such as ffmpeg, and click Add.

Glowmoth matches the executable file name, case-insensitively, including processes that start later. While one runs, the Mac is held awake with the reason "<name> is running". It checks every 5 seconds, and only while a process rule exists. This needs Keep awake automatically on (Automatic in the panel).

Fix 4: Time Machine and other backups

A backup has no single command to wrap, and you may not know its process name. Use a timed session with the display allowed to sleep:

  1. Right-click the Glowmoth icon and pick a duration under Keep This Mac Awake, such as 8 Hours.
  2. Right-click again and uncheck Keep Display On.

Or run glowmoth for 8h --no-display. A session you start keeps the screen on by default. To change that default, turn off Keep the display on under Settings… ▸ Sessions ▸ Display.

Plug a laptop in for a first large backup. If a safety limit pauses Glowmoth (see below), the backup waits until the Mac is awake again.

Fix 5: jobs scheduled for when the Mac is asleep

Glowmoth does not wake a sleeping Mac in a normal install. It can keep the Mac awake until the job's start time:

  1. Open Settings… ▸ Automation ▸ Scheduled Runs and click Add Run…
  2. Set Start at to the job's time and Stay awake for to a length (up to 4 Hours).
  3. Leave Keep awake until then on. It holds the Mac awake from now until the start time, so plug in a laptop.

Your backup app or scheduler still has to start the job. For a job longer than the run you chose, add a Process rule too.

macOS can also wake the Mac on a schedule. This wakes or powers it on at 12:55 AM every day and asks for your administrator password:

bash
sudo pmset repeat wakeorpoweron MTWRFSU 00:55:00

Undo it with sudo pmset repeat cancel. It only wakes the Mac; it doesn't hold it awake afterward, so pair it with a method above.

Which method to pick

MethodBest forNeedsLimit
caffeinate -i <command>One job from TerminalNothingNo battery or heat limit; ends with the Terminal window
glowmoth run -- <command>Scripts, exit codesGlowmoth, CLI installedNothing is held if the app's trial has ended
glowmoth wait <pid>A job already runningGlowmoth, CLI installedYou need the PID
A Process Runs… menuOne-off, no TerminalGlowmothNot saved across relaunch
Processes ruleTools you run oftenGlowmoth, Automatic onMatches by executable name
Timed session, display offBackupsGlowmothFixed length, up to 7 days

For a single job you start yourself, caffeinate is enough. Glowmoth earns its place when you want the exit code, a battery and heat limit, a rule that applies every time, or a view of what is holding the Mac.

If the job still stops

  • The lid is closed. Holding idle sleep doesn't stop lid-close sleep. Glowmoth's closed-lid mode is a separate, laptop-only setting that needs a helper approved in Login Items. See also our clamshell mode guide.
  • A safety limit paused Glowmoth. On battery it pauses below 20% by default, and it pauses when macOS reports the Mac running hot. The icon shows a slash and the panel says "Paused." Plug in or use Resume Anyway (30 min). See battery and heat limits.
  • Manual mode is on. Manual ignores everything except your own session: process rules, one-off picks, run/wait leases and scheduled runs. Switch the panel control to Automatic.
  • You chose Stop Everything. It suspends all automatic reasons until you start a session or relaunch the app.
  • The trial ended. The panel says "Your trial has ended. Enter a MacSuite license to keep your Mac awake." Nothing is held until you enter a license.
  • You slept the Mac yourself. Apple menu ▸ Sleep and the power button still sleep it.

Checklist before you try again

  • The Mac is plugged in (laptops).
  • pmset -g assertions shows an entry named "Glowmoth: …" (or caffeinate) while the job runs.
  • The panel's Held By list names your job.
  • The job is in tmux or another session that survives closing Terminal.
  • The trial or license is active and the panel is on Automatic.

If nothing works

If the Mac still sleeps with Glowmoth holding it, contact MacSuite support through our support page. Include the output of pmset -g assertions and the last lines of pmset -g log around the sleep, your macOS version, whether the lid was closed, and the exact command you ran.

text
Subject: Mac sleeps during a long job with Glowmoth running

Glowmoth 1.0.0 on macOS [version], [MacBook / desktop].
Command: glowmoth run -- [your command]
Expected: Mac stays awake until the job ends.
Actual: job paused at about [time]; pmset -g log shows Sleep at [time].
Panel state at the time: [Awake / Paused / Sleep Allowed]
Attached: pmset -g assertions output and pmset -g log excerpt.

Common questions

Does the job really pause when only the display is off?

Usually not. Most processes keep running while only the display sleeps. If yours stopped, check the power log for a full system sleep.

Will glowmoth run stop my Mac sleeping if I close the lid?

No. Holding idle sleep doesn't override a lid close. Closed-lid mode is a separate, laptop-only setting.

Can Glowmoth wake the Mac for a 1 AM backup?

Not in a normal install. It can keep the Mac awake until the start time through Scheduled Runs, or you can use pmset repeat to schedule a wake.

Is the screen kept on while the job runs?

Not with glowmoth run, wait or a Process rule. Add --display to run if you want it on.

Glowmoth is part of MacSuite and you can try it free for 7 days. See the Glowmoth page and the command-line docs.

Every app.
One purchase.