There are three ways to stop a Mac from going to sleep. You can change the sleep settings in System Settings, which works all the time. You can run caffeinate in Terminal, which works while the command runs. Or you can use a menu bar app that keeps the Mac awake for as long as you pick, then turns itself off.

Which one fits depends on whether you want your Mac awake always, just for one long job, or a few times a day for a set time.

Why does my Mac go to sleep in the middle of something?

macOS turns off the display and then sleeps the Mac after a while without keyboard or mouse input. It does not know you are reading a long document, watching a build, sharing your screen in a call, or waiting for a big download. Some apps ask macOS to stay awake while they work, but many don't.

1. Change the sleep settings in System Settings

On macOS 13 and later:

  • Open System Settings → Lock Screen. Set "Turn display off on power adapter when inactive" (and "on battery" on a MacBook) to a longer time, or to Never.
  • On a MacBook, open System Settings → Battery → Options and turn on "Prevent automatic sleeping on power adapter when the display is off". On a desktop Mac the same switch is under Displays → Advanced.

Good for: a Mac that should never sleep, like a home server. Not so good for a laptop you carry around, because you have to remember to change it back.

2. Run caffeinate in Terminal

caffeinate comes with macOS. It keeps the Mac awake while it runs.

  • caffeinate -d keeps the display and the Mac awake until you press Control-C.
  • caffeinate -d -t 3600 does the same for 3600 seconds (one hour), then stops.
  • caffeinate -i lets the display turn off but keeps the Mac running, which is useful for downloads and long scripts.
  • caffeinate -i make build keeps the Mac awake until that command finishes.

Good for: developers and long jobs started from Terminal. The catch is that it lives in a Terminal window. Close the window and it stops, and there is nothing in the menu bar that tells you it is on.

3. Use a menu bar app with a timer

A keep-awake app puts a switch in the menu bar. This is what I made Brewake for. It is a cup. Click it and pick how long: ∞, 1 to 45 minutes, or 1 to 8 hours. While it is on, your Mac does not go to sleep and the display does not dim, and the cup is full so you can see that it is on. When the time is up, Brewake turns itself off.

Good for: the everyday cases, like a 2-hour download, a 45-minute presentation or a call where you share your screen, without opening Terminal or changing settings and forgetting to change them back.

It runs on macOS 13 or later, on Apple Silicon and Intel. 7-day trial, then $2.99 once. No account and no tracking.

Which one should I use?

  • The Mac should never sleep: change the settings.
  • One long job from Terminal: caffeinate -i with the command after it.
  • A few times a day, for a set time, from anywhere: a menu bar app with a timer.

Questions

Will my Mac stay awake with the lid closed? Usually not. A MacBook goes to sleep when you close the lid, unless it is plugged in and connected to an external display, keyboard and mouse. caffeinate -d and keep-awake apps stop idle sleep, not lid sleep.

Does it drain the battery? Yes, more than sleep does, since the display stays on. A timer helps, because it turns itself off when you forget.

Is it safe? Yes. These all use the same macOS power settings that video players and presentation apps use. You can see what is keeping your Mac awake with pmset -g assertions in Terminal.

Originally posted on the Brewake blog.