Power Management in detail: using pmset

The Energy Saver pane in System Preferences does not give you full access to all the capabilities of your Mac. Even desktop models have more than a dozen different controls to determine their sleep and related behaviours. The best way to gain full access, whether you’re trying to fix your Mac’s aberrant sleeping habits, or tweak something crucial, is to use pmset at the command line.

Inspecting

Macs differ in their power management capabilities, so the first command that you’ll need is
pmset -g cap
which lists what is available. On this iMac17,1, it runs to
Capabilities for AC Power:
displaysleep
disksleep
sleep
womp
autorestart
halfdim
gpuswitch
standby
standbydelay
powernap
ttyskeepawake
hibernatemode
hibernatefile
autopoweroff
autopoweroffdelay

There is an additional system-wide power setting, DestroyFVKeyOnStandby, which determines whether the FileVault key is destroyed when your Mac goes into standy or hibernate mode. Normally that is set to 0, which preserves the key, but if you want to secure your encrypted hard disk, you will probably want to set it to 1: then waking it from hibernation will require the user to enter the FileVault passphrase, and if they fail to do so, they cannot try to recover the key from memory.

The meaning of these settings is generally obvious:

  • displaysleep is the time in minutes before the display is put to sleep; 0 indicates that the display is never put to sleep;
  • disksleep is the time in minutes before hard disks are spun down and put to sleep; 0 means never;
  • sleep is the time in minutes to system sleep; 0 means never;
  • womp is 1 if you want your Mac to wake when it receives a ‘magic’ network packet, which is the same as wake for network access in the pane;
  • autorestart sets whether your Mac will automatically restart when power loss has occurred and power has been restored;
  • halfdim sets whether an intermediate (rather than full) dimming is used for display sleep;
  • gpuswitch sets GPU behaviour during sleep, and appears to be undocumented;
  • standby sets whether to hibernate when a Mac has been asleep for a set period; this writes memory to disk and powers down memory;
  • standbydelay is the delay in seconds between going to sleep and switching to standby mode;
  • powernap sets whether your Mac will take Power Naps, where supported;
  • ttyskeepawake can prevent sleep when a text input, such as a remote login session, is active;
  • hibernatemode is set to 0 for plain sleep (desktops), 3 to store a copy of memory to disk and keep memory powered up (laptops), or 25 for full hibernation in which memory is powered down too;
  • hibernatefile sets the location of the cache to be used when going into standby mode, which must be on the boot disk;
  • autopoweroff sets whether to go into low-power sleep or standby mode;
  • autopoweroffdelay is the delay in seconds between going to sleep and going into low-power sleep or standby mode;
  • lidwake sets a laptop to wake when its lid is opened;
  • sms sets whether to use the Sudden Motion Sensor to park hard disk heads if there is a sudden jolt.

There are a couple of other settings which you can view using man pmset.

You can inspect current settings using
pmset -g
which here returns:
System-wide power settings:
DestroyFVKeyOnStandby 0
Currently in use:
standby 1
Sleep On Power Button 1
womp 1
halfdim 1
hibernatefile /var/vm/sleepimage
powernap 0
gpuswitch 2
autorestart 0
networkoversleep 0
disksleep 0
sleep 0
autopoweroffdelay 28800
hibernatemode 0
autopoweroff 0
ttyskeepawake 1
displaysleep 180
standbydelay 10800

UPS

If you have a supported uninterruptible power supply (UPS) connected, you can check its settings using
pmset -g ups
which will typically return something like
UPS settings:
haltlevel off 0
haltafter on 2
haltremain off 0

The three settings here are:

  • haltlevel – the % battery level at which to start an emergency shutdown,
  • haltafter – the time in minutes after switching to UPS power at which to start an emergency shutdown,
  • haltremain – the remaining time in minutes available on UPS power at which to start an emergency shutdown.

So according to my settings above, when my Mac is running off its UPS battery, it will start making an emergency shutdown after two minutes on that supply. These match the settings you can make in the Energy Saver pane.

upsenergysaver

Even though you might have your laptop connected to a UPS, portable Macs do not use UPS emergency shutdown settings; in the event of power outage, including the UPS shutting down during a prolonged mains failure, laptops use their internal batteries and follow their own sleep and shutdown settings instead.

You can also schedule automated power on, shutdown, wake, and sleep events, which are detailed in man pmset.

Setting

Using pmset to change Power Management settings requires you to have elevated privileges, so must be prefaced by sudo. For example, to set a Mac so that it destroys its FileVault key when going to standy/hibernation mode, you should enter
sudo pmset -a DestroyFVKeyOnStandby 1
then authenticate with your admin password.

When setting values, you will normally need to specify which group of settings are to be affected. This is determined by options:

  • -b changes a setting when on battery power (laptops),
  • -c changes a setting when on charger (mains) power (laptops),
  • -u changes a setting for the UPS, as detailed above,
  • -a changes a setting for all circumstances (laptops and desktops).

To set the time before a Mac goes to sleep to 20 minutes, you can therefore use the commands

  • sudo pmset -b sleep 20 for a laptop running off its internal battery,
  • sudo pmset -c sleep 20 for a laptop running off its mains charger,
  • sudo pmset -a sleep 20 for any Mac and all circumstances.

If you get the settings into a mess and don’t know what to do,
sudo pmset restoredefaults
should work just like the button to restore defaults in Energy Saver (which you could use instead), and sets everything back to the default settings for that model.

To set a desktop Mac to start emergency shutdown when it has been running on UPS power for 5 minutes, you would use
sudo pmset -u haltafter 5

There are a couple of other useful features in pmset:

pmset resetdisplayambientparams
will reset the ambient light parameters for those Apple displays which support ambient light adjustments;

caffeinate
can create an ‘assertion’ in OS X / macOS which will prevent sleeping of a particular system. It is fully documented by man caffeinate

Like the Energy Saver pane, settings are stored in a preference file, and acted on through the Power Management system and your Mac’s power management hardware. Until recently (Sierra 10.12.2), settings have been kept in /Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist, with scheduled events in /Library/Preferences/SystemConfiguration/com.apple.AutoWake.plist. However, in 10.12.2 the former file has moved back to /Library/Preferences/com.apple.PowerManagement.plist for unknown reasons, and in 10.12.3 the file is now named PowerManagement.[UUID].plist, where [UUID] is replaced by your hardware UUID.

They are also shown in the Power item in System Information (About This Mac, then click on System Report).

Diagnostics

You can use pmset to diagnose odd sleep behaviour in laptops. For example, if your MacBook Pro seems to keep going to sleep suddenly when it has less than 50% of its battery remaining, open a window in Terminal and type
pmset -g pslog

Then when the problem next occurs, wake your Mac and look for sudden falls in the indicated power remaining, such as a drop from 30% to almost nothing. These are typical of an ageing battery which needs to be replaced.

energysaver9

(Updated 23 January 2017 for 10.12.3)