How to Use the Hidden ‘Caffeinate’ Command on Mac to Stop Sleep Mode

The Problem with Mac Sleep Mode

By default, macOS is aggressively tuned to save battery life. If you step away from your MacBook to make a cup of coffee, the screen will likely dim within a few minutes, and the hard drive will go to sleep shortly after. This power management is excellent for battery longevity, but it can be incredibly frustrating if you are in the middle of a large file download, rendering a long video in Final Cut Pro, or running a complex script that requires continuous processing.

Many users solve this problem by downloading third-party applications like "Amphetamine." While these apps are great, you do not actually need to install extra software to keep your Mac awake. Apple has built a powerful, hidden command-line utility directly into macOS designed specifically for this purpose.

It is appropriately named: caffeinate.

How to Use the Basic Caffeinate Command

The caffeinate command prevents your Mac from going to sleep for as long as the command is actively running in the terminal window.

  1. Open the Terminal application on your Mac (you can find it by pressing Command + Space to open Spotlight Search, typing "Terminal," and pressing Enter).
  2. In the Terminal window, type the following single word:
    caffeinate
  3. Press Return (Enter).

You will not see a success message; the cursor will simply drop to a new line and sit there. As long as this Terminal window remains open and the command is running, your Mac will absolutely refuse to go to sleep. The screen may still dim depending on your display settings, but the system itself will remain wide awake.

How to Stop the Caffeinate Command

Because the command runs continuously, your Mac will stay awake forever, eventually draining the battery if it is not plugged in. You must manually tell the command to stop when your download or rendering task is complete.

  1. Go back to the Terminal window where caffeinate is currently running.
  2. Press the keyboard shortcut Control + C.

This is the universal command to cancel a running terminal process. The command prompt will return, indicating that caffeinate has stopped and your normal energy-saving sleep settings are active again.

How to Set a Specific Time Limit

If you know a download is going to take approximately one hour, and you want your Mac to go to sleep immediately after it finishes, you can tell caffeinate to run for a specific duration. This prevents you from forgetting to turn it off.

The duration must be calculated in seconds. For example, 1 hour is 3600 seconds. 2 hours is 7200 seconds.

  1. Open Terminal.
  2. Type caffeinate -t followed by a space, and then the number of seconds. For example, to keep the Mac awake for exactly one hour, type:
    caffeinate -t 3600
  3. Press Return.

The command will run silently in the background for exactly 3600 seconds. Once the timer expires, the command will automatically terminate, and your Mac will go to sleep based on its normal system settings.

How to Keep the Mac Awake Until a Specific App Closes

This is the most powerful feature of the caffeinate command. If you are rendering a video in Adobe Premiere, you can tell the terminal to keep the Mac awake only while Premiere is running. As soon as you quit Premiere, the Mac can sleep again.

  1. First, you need to find the Process ID (PID) of the application you want to monitor. Open the Activity Monitor app (search for it in Spotlight).
  2. Find the application in the list (e.g., Adobe Premiere Pro).
  3. Look at the number listed in the PID column next to the app name (for example, "1492").
  4. Open Terminal.
  5. Type caffeinate -w followed by a space, and then the PID number. For example:
    caffeinate -w 1492
  6. Press Return.

The terminal will now monitor process 1492. As soon as you close Adobe Premiere, the terminal will instantly stop the caffeinate command, allowing your system to rest.

Leave a Reply

Your email address will not be published. Required fields are marked *

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.

Receive our best articles and tips delivered straight to your inbox.