How to stop your Mac sleeping while a download or script runs

You start a big download or a long script, walk away, and come back to a sleeping Mac and a job that stopped halfway. Here's how to keep it awake for exactly as long as the work takes, with tools already on your Mac.

Keep it awake from your notchNotchDodo, $9.99 one-time
The short answerOpen Terminal and put caffeinate -i in front of the command, for example caffeinate -i ./backup.sh. Your Mac stays awake until the command finishes, then sleeps normally. For a download in an app, run caffeinate -i on its own and press Control-C when it's done. With no Terminal at all: on a MacBook, plug it in and turn on System Settings → Battery → Options → Prevent automatic sleeping on power adapter when the display is off. Closing a MacBook lid still puts it to sleep; see the lid section for that.

Why your Mac sleeps in the middle of a download

macOS puts the Mac to sleep after a while without keyboard or trackpad input. Apps can tell macOS they're busy (it's called a power assertion), and many do while playing video or running a backup. But plenty of downloads, scripts, builds and command-line tools don't, so as far as macOS can tell, nobody is using the Mac and it goes to sleep. Network transfers stop, the script pauses, and some downloads have to start over.

Two things often get mixed up here. The display turning off doesn't stop anything; your download carries on with a black screen. The Mac sleeping is what stops the work. So the goal is to stop system sleep while letting the display turn off, which also saves power.

Method 1: the built-in setting

This is the no-Terminal option, and it's in Apple's own guide. It works while the Mac is plugged in.

On a MacBook

  1. Plug your MacBook into power.
  2. Open System Settings and click Battery in the sidebar.
  3. Click Options.
  4. Turn on Prevent automatic sleeping on power adapter when the display is off.

On an iMac, Mac mini, Mac Studio or Mac Pro

  1. Open System Settings and click Energy.
  2. Turn on Prevent automatic sleeping when the display is off.
The catch: this stays on until you switch it off, for every job and every night. That's fine for a Mac that lives on a desk, but if you only need it awake for tonight's download, the next two methods turn themselves off when the work is done.

Method 2: caffeinate in Terminal

Every Mac has a small built-in tool called caffeinate that keeps it awake for as long as you ask. It's the most precise option, because it can tie "awake" to a specific job. Open Terminal (Command-Space, type Terminal, press Return) and pick the line that fits.

Until a script or command finishes

Put caffeinate -i in front of the command. The Mac stays awake while it runs and is free to sleep the moment it ends:

Terminal
caffeinate -i ./backup.sh

The same works for a download you start from Terminal:

Terminal
caffeinate -i curl -O https://example.com/big-file.zip

Until an app finishes

For a download in an app that's already running, give caffeinate that app's process id with -w. It waits for the app to quit, then lets the Mac sleep. Replace Transmission with the app's name:

Terminal
pgrep -x "Transmission"     # prints the app's process id, e.g. 4821
caffeinate -i -w 4821

For a set time

To keep the Mac awake for two hours (7,200 seconds) and then stop on its own:

Terminal
caffeinate -i -t 7200

Or run caffeinate -i on its own and press Control-C when you're done.

Terminal window showing caffeinate -i ./backup.sh, pgrep for an app followed by caffeinate -i -w with its process id, and caffeinate -i -t 7200
Three ways to use caffeinate: until a script ends, until an app quits, or for a set time.

Which flag do you need?

FlagWhat it doesUse it when
-iStops idle system sleep. The display can still turn off.Downloads, scripts, builds. The one you usually want.
-dKeeps the display on too.You need to watch the screen, such as a presentation or a progress bar.
-sStops system sleep, but only on AC power.A desk Mac that should never sleep while plugged in.
-mStops the disk idle sleeping.Rarely needed on Macs with an SSD.
-t 3600Stops after that many seconds.You know roughly how long the job takes.
-w PIDStops when that process exits.An app or command that's already running.

These come straight from the caffeinate manual page (type man caffeinate to read it). With no flags at all, caffeinate behaves like -i.

How to check what is keeping your Mac awake

Not sure caffeinate is working, or wondering why your Mac won't sleep? macOS keeps a list. This one-liner shows who is holding sleep off right now:

Terminal
pmset -g | grep " sleep "

And this one lists every assertion with the app that owns it and why:

Terminal
pmset -g assertions
Terminal output of pmset showing sleep prevented by caffeinate and NotchDodo, and pmset -g assertions listing a caffeinate assertion for 30 seconds and a NotchDodo assertion named Claude Code is working
Real output from our Mac, trimmed: a 30-second caffeinate and NotchDodo holding the Mac awake while Claude Code works.

Look for PreventUserIdleSystemSleep 1 in the summary and the owners listed below it. You'll often see system processes there too, such as powerd while the display is on; that's normal.

Method 3: a free keep-awake app

If you'd rather click than type, these menu bar apps wrap the same macOS feature in a button:

  • Amphetamine (free, Mac App Store). The most flexible: sessions for a set time, until an app quits, or until a file finishes downloading, plus triggers that start a session automatically.
  • KeepingYouAwake (free, open source). A coffee cup in the menu bar with preset durations. Simple and lightweight.

Both are good. The trade-off is one more icon in a menu bar that, on a MacBook with a notch, may already be hiding icons behind it.

Method 4: one tap in your notch

NotchDodo turns the MacBook notch into a small dashboard, and keep-awake is built in two ways.

The Keep awake toggle

In the Dashboard's Quick toggles, tap the coffee cup and the Mac and its display stay awake until you tap it again.Right-click the cup for more:

  • For 30 minutes to 4 hours, then it lets go.
  • Until downloads finish. It watches your Downloads folder, lets the screen turn off, and lets the Mac sleep 20 seconds after the last download lands.
  • Until an app quits. Pick any open app from the list.

When it turns itself off, a banner tells you why, with a button for one more hour. Under the hood it runs macOS's own caffeinate, so it shows up in pmset -g assertions like the command above.

NotchDodo Dashboard open under the MacBook notch, with the coffee cup Keep awake button in the Quick toggles tile
The coffee cup in Quick toggles. Tap for on and off, right-click for a timer, downloads or an app. Demo data.

Automatic while AI agents work

If your long-running job is an AI coding agent such as Claude Code, Codex, Gemini CLI or Grok, you don't have to remember anything. NotchDodo notices when an agent is working, keeps the Mac awake (the display can still turn off), and lets it sleep once every agent has finished. Lock the screen and walk away, and it can even put the Mac to sleep when the work is done instead of hours later. More about keeping your Mac awake for AI agents.

NotchDodo AI Usage panel listing running agent sessions, with the green coffee cup in the header showing the Mac is being kept awake
The green cup in AI Usage: the Mac is staying awake because agents are running. Demo data.

What about closing the lid?

Closing a MacBook's lid puts it to sleep, and the System Settings switch, caffeinate and NotchDodo don't change that. caffeinate stops idle sleep, not lid sleep. Your options:

  • Leave the lid open and let the display turn off. The simplest and safest.
  • Closed-display mode. Apple supports running a MacBook closed when it's connected to power, an external display, and a keyboard and mouse or trackpad. See Apple's guide to using a MacBook with an external display (and our full guide to keeping a MacBook awake with the lid closed).
  • Amphetamine has its own closed-display mode that can keep a MacBook awake with the lid shut. Watch the heat if it's in a bag or on a soft surface.
  • Not recommended: sudo pmset -a disablesleep 1 is an undocumented setting that stops lid sleep. A closed MacBook in a bag can get very hot, and the setting stays on until you run it again with 0. Use it only if you know why you need it.

Which method should you use?

System SettingscaffeinateAmphetamineNotchDodo
No Terminal neededYesNoYesYes
Stops on its own when the job endsNoYesYesYes
Works on batteryNo, plugged in onlyYesYesYes
Keeps the lid-closed Mac awakeNoNoYes, its closed-display modeNo
Where you turn it onSettings appTerminalMenu barThe notch
CostFree, built inFree, built inFree$9.99 one-time, with 17 more tools

For a one-off download, caffeinate -i is hard to beat: nothing to install and it switches itself off. If you never want a desk Mac to sleep while plugged in, use the System Settings switch. If you run AI agents or long jobs every day, having it handled from the notch saves you thinking about it.

Keep your Mac awake from the notch.Keep it awake for a set time, until downloads finish or until an app quits, and automatically while AI agents work. Plus calendar, clipboard, Pomodoro and 15 more tools. One-time purchase, no subscription.Get NotchDodo for $9.99See all 18 tools

Sources

Mac, MacBook and macOS are trademarks of Apple Inc. Amphetamine and KeepingYouAwake belong to their developers. NotchDodo is an independent app and is not affiliated with Apple.

Frequently asked questions

How do I stop my Mac from sleeping during a download?

The quickest way is Terminal: run caffeinate -i and leave the window open until the download finishes, then press Control-C. If the download is in a command such as curl, put caffeinate in front of it (caffeinate -i curl -O <url>) and the Mac stays awake exactly as long as the download runs. On a MacBook you can also turn on System Settings > Battery > Options > "Prevent automatic sleeping on power adapter when the display is off" and keep it plugged in.

Does the Mac keep downloading when the screen turns off?

Usually yes, as long as the Mac itself doesn't go to sleep. The display turning off and the Mac sleeping are two different things. caffeinate -i and the System Settings switch stop the Mac sleeping but let the display turn off, which saves power and is all a download needs.

What does caffeinate -i do?

It tells macOS not to idle sleep the system while caffeinate is running. -d also keeps the display on, -s keeps the whole system awake but only on AC power, -t sets a timeout in seconds, and -w waits for a given process id to exit. Put a command after caffeinate and the Mac stays awake until that command ends.

How do I stop caffeinate?

Press Control-C in the Terminal window where it's running, or close that window. If you started it with -t or with a command after it, it stops on its own when the timeout ends or the command finishes.

Can I keep my MacBook awake with the lid closed?

Not with caffeinate or the System Settings switch: closing the lid puts a MacBook to sleep. The supported way is Apple's closed-display mode, where the Mac is connected to power, an external display and a keyboard and mouse or trackpad. The free Amphetamine app also has a closed-display mode. There is an undocumented sudo pmset -a disablesleep 1 setting that stops lid sleep, but we don't recommend it: a closed MacBook in a bag can overheat, and it's easy to forget to turn it back off.

How do I see which app is keeping my Mac awake?

Run pmset -g assertions in Terminal. The "Listed by owning process" section names every app holding the Mac awake and why, for example caffeinate or a backup app. pmset -g | grep " sleep " gives a one-line summary.

Is it bad to keep my Mac awake all the time?

It isn't harmful to the Mac, but it uses more power and, on battery, drains it. Apple's own guide warns that preventing sleep may increase power consumption. Keep your Mac awake only while something is running, which is what caffeinate with a command, a timer, or an app that switches itself off does.

Does NotchDodo keep my Mac awake for downloads?

Yes. NotchDodo's Keep awake quick toggle has an Until downloads finish option: right-click the cup in the notch and your Mac stays awake while anything is downloading to your Downloads folder, then sleeps normally once it's done. It can also keep the Mac awake for a set time or until an app quits, using macOS's own caffeinate tool. Separately, it keeps the Mac awake automatically while AI coding agents such as Claude Code, Codex or Gemini CLI are working, and can put it to sleep when they finish.