Tips & Shortcuts

Quick Tip: How to Stop Your Mac From Sleeping Using the Command Line


Computers sleep as a way to save energy and prevent unnecessary wear on your machine's hardware. Yet there are times you may want to stop your Mac from sleeping such as when you’re watching a movie, cloning a large repository from GitHub, or need to let a large download finish from your favorite website.

When in these situations, it can be inconvenient to look through System Preferences > Energy Saver until you find the settings needed and then you must remember to re-enable your original settings when you are done. With OS X 10.8, Mountain Lion, we are able to stop our Macs from sleeping for a period of time from our command line with the caffeinate command. Let’s take a look at how to use this command, and some alternatives for older machines.

Caffeinate and How to Use It

The caffeinate command is used to prevent a Mac from going to sleep. The simplest way to use this command is to run the following command in the terminal.


When run, the cursor will move down to a blank line where it will stay until you tell the command to stop running or close the terminal. While running, caffeinate will prevent your Mac from sleeping. To stop the process from running, you can press Ctrl+C which will instantly end the process, and return you to the command prompt.

Caffeinate While Running
While running, caffeinate will leave a blank prompt.

For some situations, such as while watching a movie, this may be fine. Other times, you may prefer to set the duration you would like to prevent the Mac from sleeping. Luckily, Apple has made this rather easy to accomplish by using the -t option to your command, followed by the time in seconds. For example, if you wanted to prevent your Mac from sleeping for 5 hours, you would run the following command:

caffeinate -t 18000

The caffeinate command can also be linked to other commands, such as cloning a git repository, by linking caffeinate to a specific command. This can be done in the following way:

caffeinate [command_you_want_to_link] -arguments

Tip: The brackets around the command ([command_you_want_to_link]) are there for demonstation, but would not be used around a normal command such as open.

Using Caffeinate’s Options

Apple understands that each person using this command may have different needs and has provided a number of different options to let users decide what is needed in their situation. These options include:

  • -d — Prevent the display from sleeping.
  • -i — Prevent the system from idle sleeping.
  • -s — Prevent the system from sleeping. This is valid only when system is running on AC power.
  • -u — Declare that a user is active. If the display is off, this option turns the display on and prevents the display from going into idle sleep.
  • -t — Specifies the timeout value in seconds for which the command is valid.

To learn more about caffeinate and other ways to use the command, visit the Mac Developer Library entry on caffeinate.

Alternatives to the Command Line

Older versions of OS X, unfortunately, do not have the ability to use this command, and the convenience of an application can be difficult to beat. Luckily, developers have listened and provided a number of convenient and compatible options. Each of these includes different features, ranging from simple time settings to more advanced facical detection via the iSight camera, so I encourage you to look through them to find what best fits your needs. These include, but aren’t limited to:


In this Quick Tip we briefly covered some reasons you may want to prevent your Mac from sleeping, how to use the caffeinate command, and lastly I shared some applications that available to users who may prefer the convenience of an application or may not have Mountain Lion installed on their machine. I hope you’ve enjoyed this quick tip, if you have any questions please let me know in the comments and I’ll do my best to answer them!

Related Posts
  • Computer Skills
    5 Simple Solutions to Common Mac Problems5
    Not every problem with your Mac requires an in-depth tutorial. Some small issues can be solved with a single piece of advice: "install this app." In this tutorial, I'll tackle five such problems and introduce you to some great apps that provide quick and easy solutions. Read More…
  • Computer Skills
    How to Check and Enable TRIM on a Mac SSDTrim preview retina
    You probably know that solid state drives (SSD) differ from Hard Disk Drives (HDD) in how they store information, and you may have heard that something called TRIM can maintain their performance. In this tutorial, I’ll not only show you how you can enable TRIM support for your SSDs, but also understand what the term means and how it fits into the functionality of solid state storage.Read More…
  • Computer Skills
    OS X
    Finding Hardware Faults: Exploring AHT & Apple DiagnosticsAht preview retina
    Alongside the tools provided for identifying software issues with your Mac, Apple also makes sure that you can examine your hardware for possible faults. These hardware diagnostic tools have evolved over the years, so in this tutorial I will cover the two incarnations that exist: the venerable Apple Hardware Test (AHT), and the newer Apple Diagnostics tool that replaced it. In this tutorial I'll show you how you can use these helpful utilities to keep an eye on the components that make your Mac tick.Read More…
  • Computer Skills
    App Training
    Quick Tip: Customize the TerminalCustomizeterminal preview retina
    It’s safe to say that many Mac users will only rarely be seeing the Terminal. In our age of gorgeous UI, or User Interface, design and there’s an app for that, the need to do things the old fashioned way is diminishing. Nevertheless, when you do find yourself at the command line, you can make it look less intimidating or more like it does in the movies. In this tutorial I'll show you how you can use Terminal’s deep customization tools to spruce up the look of the app to suit your preferences. Read More…
  • Computer Skills
    40 Terminal Tips and Tricks You Never Thought You NeededIcon terminal 2x
    The Terminal is an exceptionally powerful tool, providing a command line interface to the underpinnings of OS X. It’s a topic we’ve covered at length before with our popular series Taming the Terminal. There’s a great deal that Terminal can do, from moving large numbers of files to changing preferences that we didn’t even know exist. To demonstrate just how versatile the Terminal is, I’ve rounded up 40 truly excellent Terminal tips and tricks that can come in very handy. Read More…
  • Computer Skills
    App Training
    Up and Running With the Alfred Powerpack — WorkflowsAlfred app powerpack finalpreviewretina
    In the Up and Running With the Alfred Powerpack — The Basics tutorial, we covered a number of great PowerPack features such as Syncing, Custom Searches, Email, and 1Password. I highly recommend taking a look at that if you are new to Alfred, as below we will be focusing on Workflows and some of the more advanced aspects of this feature. In this tutorial, I will be creating two types of workflows. One is a basic app launcher, that you might run when you get to work, while the other is a more in-depth look of how you can code your own workflow. I have intentionally omitted some features in the coding your own workflow section, to give you room to expand and practice what you've learned today. I encourage you to try to add more to them and share with others in the comments what you learned. The best way to learn is to share with others!Read More…