admin-plugins author calendar category facebook post rss search twitter star star-half star-empty

Tidy Repo

The best & most reliable WordPress plugins

Using Caffeinate on macOS to Prevent Sleep

Using Caffeinate on macOS to Prevent Sleep

Ethan Martinez

June 30, 2026

Blog

Your Mac loves sleep. It curls up like a cat when you stop touching it. That is usually great. It saves power. It keeps things quiet. But sometimes you need your Mac to stay awake. That is where caffeinate comes in.

TLDR: caffeinate is a built-in macOS Terminal command that keeps your Mac awake. You can use it while downloads, uploads, backups, scripts, or long jobs run. Open Terminal, type caffeinate, and your Mac stays awake until you stop it. Add simple options to control what kind of sleep you want to block.

What Is Caffeinate?

caffeinate is a tiny command on macOS. It tells your Mac, “Not yet, buddy. Stay awake.”

It does not install anything. It is already on your Mac. It works from the Terminal app. It is simple. It is quiet. It is very handy.

Think of it like a cup of coffee for your computer. Not for you. For your Mac. No beans needed.

You may need it when your Mac is doing something important. For example:

  • Downloading a huge file.
  • Uploading videos.
  • Running a backup.
  • Exporting photos.
  • Building code.
  • Running a long script.
  • Watching a long stream on an external display.

Without help, your Mac may go to sleep. Then the job may pause. Or fail. Or become weird. Nobody wants weird.

Why Use Caffeinate?

You can change sleep settings in System Settings. That works. But it can be annoying.

You may forget to change them back. Then your Mac stays awake all night. It warms your desk. It drains your battery. It makes the fan sigh.

caffeinate is better for short tasks. You turn it on when needed. You stop it when done. Easy.

It is also great because it can be tied to a command. Your Mac can stay awake only while that command runs. When the command ends, the Mac can sleep again. That is neat. Very neat.

How To Open Terminal

You use caffeinate in Terminal. Do not be scared. Terminal looks intense. But you only need a few words.

  1. Press Command + Space.
  2. Type Terminal.
  3. Press Return.

A small window appears. It may show your user name. It may show a blinking cursor. That cursor is ready. It is waiting for your magic spell.

The Simplest Command

Here is the basic version:

caffeinate

Press Return. That is it.

Your Mac will now stay awake while that Terminal command is running. The Terminal window will look like nothing happened. That is normal. It is working in silence. Like a tiny digital night guard.

To stop it, click the Terminal window and press:

Control + C

That ends the caffeinate command. Your Mac can sleep again, based on your normal settings.

Does It Keep the Screen On?

Sometimes yes. Sometimes no. It depends on the options you use.

The plain caffeinate command prevents idle sleep. That means the Mac should not fully sleep just because it is idle.

But the display may still turn off. That can be fine. The Mac is still awake. The job can still run.

If you want to keep the display awake too, use this:

caffeinate -d

The -d option means “prevent display sleep.” Your screen stays on. Great for presentations. Great for monitoring progress. Bad for battery life. Use it wisely.

Common Caffeinate Options

Here are useful options. They look a little cryptic. But they are simple once translated.

  • -d keeps the display awake.
  • -i prevents idle system sleep.
  • -s prevents system sleep while on AC power.
  • -u tells the system the user is active.
  • -t sets a timer in seconds.
  • -w waits for a process to finish.

You can combine options. For example:

caffeinate -d -i

This keeps the display awake and prevents idle sleep. It is like saying, “Eyes open. Brain on.”

Image not found in postmeta

Use a Timer

Maybe you only need your Mac awake for one hour. You do not need to babysit it. Use -t.

The timer uses seconds. Yes, seconds. Computers love making you do tiny math.

One hour is 3600 seconds. So you can run:

caffeinate -t 3600

Your Mac stays awake for one hour. Then caffeinate stops.

Here are more examples:

  • caffeinate -t 600 keeps awake for 10 minutes.
  • caffeinate -t 1800 keeps awake for 30 minutes.
  • caffeinate -t 7200 keeps awake for 2 hours.

Want the display awake too?

caffeinate -d -t 3600

Now the screen stays on for one hour.

Run a Command With Caffeinate

This is where caffeinate becomes extra cool.

You can place a command after it. Then macOS stays awake only while that command runs.

For example:

caffeinate curl -O https://example.com/bigfile.zip

This keeps your Mac awake while curl downloads the file. When the download finishes, caffeinate ends too.

Another example:

caffeinate python3 longscript.py

Your Mac stays awake while the Python script runs. When the script ends, nap time can return.

This is clean. It is tidy. It is the “set it and forget it” style.

Use Caffeinate During Backups

Backups can take a long time. Especially the first one. Your Mac may want to sleep halfway through. That is rude.

If you are starting a manual backup, you can run:

caffeinate -i

Then start your backup. Keep Terminal open. When the backup finishes, press Control + C.

If you know the backup may take two hours, use:

caffeinate -i -t 7200

Now you have a two-hour awake window. Perfect for tea, snacks, or staring at a progress bar like it owes you money.

Use Caffeinate for Downloads

Large downloads are a classic use. Maybe you are downloading a game. Maybe a giant video file. Maybe a software update. The file is huge. Your patience is small.

Open Terminal and run:

caffeinate -i

Then start the download in your browser. Your Mac should stay awake while the download continues.

If you want to see the download progress, keep the screen awake too:

caffeinate -d -i

Just remember. Keeping the screen on uses more power. If you are on battery, be careful.

Battery Warning

caffeinate is useful. But it is not magic. If your MacBook is unplugged, it can still run out of battery.

If the battery dies, your task may stop. Your Mac may shut down. Your download may cry quietly.

For long tasks, plug in your charger. This is the boring advice. It is also the good advice.

Use -s if your Mac is plugged in and you want to prevent system sleep on AC power:

caffeinate -s

This option works when connected to power. It is useful for desktops and plugged-in laptops.

How To Stop Caffeinate

If caffeinate is running in Terminal, stopping it is easy.

Press:

Control + C

That sends an interrupt. In human words, it means “please stop now.”

You can also close the Terminal window. Terminal may ask if you want to close the running process. Confirm only if you mean it.

If you started caffeinate in the background, you may need to find it. Run:

ps aux | grep caffeinate

Look for the process ID. Then use:

kill PROCESSID

Replace PROCESSID with the real number. Be careful. Do not randomly kill things. Your Mac is not a piñata.

Make It Run in the Background

Sometimes you want to keep using the same Terminal window. Add an ampersand:

caffeinate -i &

This starts caffeinate in the background.

Terminal will show a job number and process ID. Save that if you want. You can stop it later with kill.

For most beginners, the normal foreground method is easier. Open Terminal. Run caffeinate. Leave it there. Press Control + C when done.

Check Your Energy Settings Too

caffeinate is great. But your Mac also has energy settings.

You can check them in:

  1. System Settings.
  2. Displays or Battery.
  3. Lock Screen or related sleep options.

The exact names can change by macOS version. Apple likes moving furniture.

If something still sleeps too soon, check those settings. Also check if your Mac is in low power mode. That can affect behavior.

Image not found in postmeta

Caffeinate vs Apps

There are apps that keep your Mac awake. Some sit in the menu bar. Some have cute icons. Some are excellent.

So why use caffeinate?

  • It is already installed.
  • It is free.
  • It is fast.
  • It works in scripts.
  • It does not need a menu bar icon.

Apps are nice if you prefer clicking. caffeinate is nice if you like simple commands. Both can be useful.

Easy Recipes

Here are quick recipes you can copy.

Keep the Mac awake until you stop it:

caffeinate

Keep the screen on too:

caffeinate -d

Keep awake for 30 minutes:

caffeinate -t 1800

Keep screen and system awake for one hour:

caffeinate -d -i -t 3600

Run a script and stay awake until it ends:

caffeinate ./myscript.sh

Prevent idle sleep while plugged in:

caffeinate -s

Small Gotchas

There are a few things to know.

  • Closing the lid may still sleep a MacBook, unless you use clamshell mode with power and an external display.
  • Battery can still run out. Caffeinate does not create electricity.
  • Display sleep and system sleep are different. Pick the right option.
  • Some apps have their own behavior. They may pause for other reasons.
  • Remote sessions can end if the network changes or power fails.

Most of the time, it just works. But these details help when it does not.

Final Thoughts

caffeinate is one of those tiny Mac tools that feels like a secret button. It is simple. It is built in. It solves a real problem.

Use it when your Mac needs to stay awake for a job. Use a timer when you want safety. Use -d when the display must stay on. Use -i for idle sleep. Press Control + C when finished.

Your Mac can still nap later. But for now, give it a little digital coffee. Let the downloads finish. Let the backups run. Let the scripts do their thing. Sleep can wait.