How to customise the power settings from Terminal on the Mac

How to use commands int he Terminal window to control the power settings on the Apple Mac. Use pmset, caffeinate and systemsetup.

Sometimes you want to stop the Mac from entering sleep mode, or you need the screen to stay on. System Preferences can do that, but more powerful commands are available from the Terminal.

Go to Energy Saver in System Preferences and you can set the timeout for the display to turn off and the time to wait before putting the computer to sleep when it is inactive. If the Mac has a hard disk drive, it can be put to sleep when possible.

These controls are OK for most people, but there are a couple of commands available from the Terminal that go far beyond these simple settings and they let you control how the Mac behaves in great detail.

Get a shot of caffeine

For years there has been a free utility for the Mac called Caffeine that stops the computer entering sleep mode automatically. It was useful for those occasions when you wanted to run a program or wait for something to finish without macOS assuming the Mac is idle and putting it to sleep.

Perhaps Apple liked the app and the name, because there is a utility in macOS called caffeinate that stops the Mac entering sleep mode. It keeps it awake.

Open a Terminal window and type caffeinate. It prevents the Mac fdrom entering sleep mode until you quit the command by pressing Ctrl+Z and then type killall caffeinate.

Stop the Mac entering sleep mode with the caffeinate command in Terminal

Caffeinate can prevent sleep for a certain length of time, measured in seconds. The following command prevents the Mac from sleeping for one hour - 60 x 60 seconds.

caffeinate -t 3600

Here is a command that prevents anything from sleeping for one hour:

caffeinate -dismu -t 3600

d = Prevent the display from sleeping
i = Prevent the system from idle sleeping
s = Prevent the system from sleeping on mains power
m = Prevent hard disks from sleeping
u = Says the user is active

Use the systemsetup command

There is another command that can be used to control if and when the Mac enters sleep mode called systemsetup. It is a general purpose command for configuring system settings and it does a lot more than just control sleep mode.

The following commands get information and they do not change anything. Try them by entering them at a Terminal command prompt.

sudo systemsetup -getcomputersleep
sudo systemsetup - getdisplaysleep
sudo systemsetup -getharddisksleep

The sudo simply means run as an administrator, and you’ll be asked for your password.

Use the systemsetup command from the Terminal command prompt on the Apple Mac

Instead of -get, you can use -set like this:

sudo systemsetup -setcomputersleep 60
sudo systemsetup -setdisplaysleep 10
sudo systemsetup -setcomputersleep Never

The caffeinate command required the time in seconds, but systemsetup uses minutes, so the commands above set the computer to sleep after 60 minutes, the display after 10 minutes, and the Mac to never sleep.

Use the pmset command

Pmset is a Terminal command for reading and writing many power management settings. To see a list of the settings, enter:

pmset -g

The pmset command has a huge number of options and it is impossible to cover them all here. They are all documented in the manual (see below) and it runs for page after page!

The pmset command in a Terminal window on the Apple Mac

Here are some very simple examples of using the pmset command:

sudo pmset -a displaysleep 7
sudo pmset -a sleep 30
sudo pmset -a displaysleep 5 disksleep 10 sleep 20

Sudo is required because pmset is only available to administrators. You may be asked for your password.

The number is the number of minutes.

-a means all power sources. Replace with -b to make the setting apply to battery only, or with -c for when the charger is plugged in.

This tells the Mac to sleep after 15 minutes idling with no activity on battery:

sudo pmset -b sleep 15

Read the manual!

All of these commands are well documented and you can read the manual with:

man caffeinate
man systemsetup
man pmset

Use the up/down arrows on the keyboard to scroll up and down and Q to quit. Take care with Terminal commands and always make sure you have a backup!

 

Share

Add new comment

By submitting this form, you accept the Mollom privacy policy.

Related items you will like...