Commands for Taking Control Over Mac's Sleep Features

Commands for Taking Control Over Mac's Sleep Features

11K 190K

Hello, dear Mac users!
I'm glad to see you here again and I'm going to tell you some useful tips on controlling the sleep functions of your Mac.

Macs are believed to be power efficient thanks to their optimized schedule of sleeping on OS X. Still, in some situations you won't want your machine to sleep, for example, while downloading some large file, reviewing a spreadsheet, reading a book or analyzing content from the screen. I can continue this list nearly forever... To cope with this issue, visit 'System Preferences' and play with your settings. But this can become a problem, if you need to do this too often.
So, I want to tell you about different comfortable ways of dealing with this dilemma!

A classic and the first option that comes to mind is a free Caffeine program. Recent OS X versions made some changes to the sleeping mode, and there is a comfortable built-in app for inducing insomnia. The Caffeinate aptly is a utility looking like a command line and can be accessed with Terminal. As you could already suggest, you should run a command there and your Mac won't get asleep until you turn it off.
It can be run in a classic way or be modified and customized basing on your preferences and needs. You can add a timer, target a process or program, or modify some specific sleep options.

By the way, I have recently found a cool app for Mac called Setapp, subscription to which allows me to save money and access more than 100 popular Mac apps. Try it too (Setapp it’s free for Download).

 

Step 1. Launch Terminal

As I've said before, Caffeinate can be accessed via Terminal. Find it in the Spotlight search, or Launchpad, or 'Applications' > 'Utilities', and open it.

mac sleep commands image4

Step 2. Run the command 'Caffeinate'

Once you run this command in Terminal, you Mac will be prevented from going asleep. It will be active all the time while Terminal is active.

Type in: 'caffeinate' inside your Terminal and press Enter.

Terminal will show you 2 small actions that can tell you that it is active now. The red spotlight highlighted with a dot and a red arrow tells us that Terminal is running some command at the moment. And an unavailable cursor indicated by a blue arrow tells us that that command is being carried out currently.

mac sleep commands image3

Step 3. How to stop it

If you need to stop Caffeinate, press Ctrl+C keyboard keys while you are using Terminal. Maybe you already know that it is a classic combination that stops the current commands in Terminal. So, your Mac will restore its usual sleep cycle after you press this key combination.

As I've noted before, the command of Caffeinate can work by itself or with some modifiers. Here are several useful ones:

 

Adding a timer

Let's pretend that you need your Mac to run some process for about an hour and then it would get back to its usual cycle. Modify the Caffeinate command: caffeinate -t 3600

  • '-t' - adds a times
  • '3600' - is the amount of seconds you need.

mac sleep commands image2

Choosing a certain app/process

Another modifier type is attaching Caffeinate to an app or some system process. The main benefit of doing that is the fact that your system won't fall asleep while a certain process or application is running. For instance, if you want to choose Final Cut Pro as such app, modify the command the following way:

  • caffeinate /Applications/Final\ Cut\
  • Pro.app/Contents/MacOS/Final\ Cut\ Pro

mac sleep commands image1
It is much simpler than it can seem at the start. So, the first part was just the 'caffeinate' command, and as for the second one, it was a location of a program of your choice. In our case, it was Final Cut Pro.

More specific modifier flags for Caffeinate


Here are few other useful options you can use in your everyday work with the app:

  • -d is for preventing Mac's display from falling asleep
  • -i can prevent OS X from idle sleeping
  • -m is for preventing the disk from falling asleep
  • -s can prevent Mac from going to sleep while it is plugged in
  • -u replicates an active Mac user at the moment

Surely, all these options can be chosen for different scenarios. For instance, if you want to watch some series on Netflix and take a sleep after it, combine that pieces in one command:

caffeinate -d /Applications/Firefox.app/Contents/MacOS/firefox-bin https://netflix.com

 

Benefits and limitations of Caffeinate

If you have experience of using the command line, then you surely know how to combine commands to get a right result. I have shown just a few variants in my article, but you can create new scenarios and vary them from time to time.

On the other hand, there are lots of variants that will conflict with each other, and you can make mistakes in case you are not an expert in using Terminal, especially if you have never used it before. In this situation, it is better to use the Caffeine application that is intuitive and user-friendly.

As for me, I can work with both options. Caffeine is a perfect way for quick and easy solutions, but Caffeinate is an ideal option for creating your personal scenarios.

Please share this article with your friends in the social media, if you liked it! Hope to see you again in my blog soon! ;)