Articles‎ > ‎

Power Management and Scheduling via the Command Line

posted Dec 16, 2008, 6:13 PM by Philip Rinehart   [ updated Dec 16, 2008, 6:14 PM by Greg Neagle ]
Written by Richard Glaser   
Friday, 01 June 2007

In Mac OS X, you can view & modify settings for power management using the GUI, System Preferences -> Energy Saver. But this isn't always ideal especially in a enterprise environment, because some settings aren't available via the GUI and other times you might want to programmatically view or modify these settings, like using a script, or remotely using Apple Remote Desktop or SSH.

Luckily, there is a command line tool called pmset that allows you to modify and read the power management settings. These settings includes options like idle sleep timing, wake on administrative access, automatic restart on power loss, scheduling events, and much more.

View Settings 

Using the following "pmset" command with the "-g" & "disk" flags will display settings for all power sources on disk, including those not currently in use.

For example, this is the output on a Power Mac Dual 2 GHz... 

# pmset -g disk

AC Power:
 womp           1
 powerbutton    0
 sleep          0
 acwake         0
 autorestart    1
 ring           0
 reduce         0
 disksleep      0
 displaysleep   180
 dps            0
 
  • womp - wake on ethernet magic packet
  • powerbutton - sleep the Mac when power button is pressed.
  • sleep - Mac sleep time, set in minutes.
  • acwake - wake Mac when AC or battery has changed.
  • autorestart - automatically restart after power loss.
  • ring - wake on modem access.
  • reduce - reduce Mac processor speed.
  • disksleep - disk spindown timer.
  • displaysleep - display sleep timer, set to 180 or 3 hours.
  • dps - dynamically change processor speed based on load.

Below is an example on how some pmset  settings correlates to the System Preferences -> Energy Saver pane. 

Energy Saver -> Sleep Options vs pmset


Energy Saver -> Options vs pmset


For example, this is the output on a MacBook Pro 2.33 Intel Core 2 Duo...

# pmset -g disk

Battery Power:
 sms            1
 hibernatefile  /var/vm/sleepimage
 acwake         0
 sleep          15
 halfdim        1
 hibernatemode  3
 disksleep      10
 displaysleep   5
 lidwake        1
 lessbright     0
AC Power:
 womp           1
 sms            1
 hibernatefile  /var/vm/sleepimage
 acwake         0
 sleep          0
 autorestart    0
 halfdim        1
 hibernatemode  3
 disksleep      10
 displaysleep   60
 lidwake        1
 

  • sms - Use Sudden Motion Sensor to park disk heads on sudden changes in G-force.
    Set to true (1)
  • halfdim - Display sleep will use an intermediate half-brightness state between full brightness and fully off. Set to true (1)
  • hibernatemode - When Mac goes into sleeping mode and gets the following behaviors depending on the following values. Set to hibernate mode 3.
    • 0 - Old style sleep mode, with RAM powered on while sleeping, safe sleep disabled, and super-fast wake.
    • 1 - Hibernation mode, with RAM contents written to disk, system totally shut down while “sleeping,” and slower wake up, due to reading the contents of RAM off the hard drive.
    • 3 - The default mode on machines introduced since about fall 2005. RAM is powered on while sleeping, but RAM contents are also written to disk before sleeping. In the event of total power loss, the system enters hibernation mode automatically.
    • 5 - This is the same as mode 1, but it’s for those using secure virtual memory.
    • 7 - This is the same as mode 3, but it’s for those using secure virtual memory.
  • lidwake - Wake the Mac when the laptop lid is opened. Set to true (1)
  • lessbright - Turn down display brightness when switching to this power source.

Below is an example on how some pmset settings correlates to the System Preferences -> Energy Saver pane.

Energy Saver -> Battery -> Sleep vs pmset

 Energy Saver -> AC -> Sleep vs pmset

 Energy Saver -> Battery -> Sleep vs pmset
 

Energy Saver -> AC -> Options vs pmset

For example, this is the output on a Xserve Pro 2 GHz Dual-Core Intel Xeon with attached APC UPS, using the "ups" flag with the "pmset" command...

# pmset -g ups

UPS settings:
  haltlevel     off     0
  haltafter     off     0
  haltremain    on      5

  • haltlevel - When draining UPS battery, battery level at which to trigger an emergency shutdown (value in %)   
  • haltafter - When draining UPS battery, trigger emergency shutdown after this long running on UPS power (value in minutes)
  • haltremain - When draining UPS battery, trigger emergency shutdown when this much time remaining on UPS power is estimated (value in minutes)

UPS settings also have an on/off value. Use a -1 argument instead of percent or minutes to turn any of these settings off. If multiple halt conditions are specified, the system will halt on the first condition that occurs in a low power situation.

Below is an example on how some pmset settings correlates to the System Preferences -> Energy Saver pane. 

 Energy Saver -> AC -> Options vs pmset
 

View Schedule


To display the scheduled startup/wake and shutdown/sleep events use the following command...

# pmset -g sched

For example, here is the repeating event schedule that startups at 7:00 AM and shutdowns at 12:00 AM each day.

# pmset -g sched

Repeating power events:
  wakepoweron at 7:00AM every day
  shutdown at 0:00AM every day
Scheduled power events:
 [0]  wakeorpoweron at 05/24/07 07:00:00 by Repeating
 [1]  wakeorpoweron at 05/24/07 07:00:00 by Repeating
 [2]  shutdown at 05/24/07 00:00:00 by Repeating

Energy Saver -> Options-> Schedule Repeating

For example, here is the repeating event schedule that shutdowns at 12:00 AM on the weekends, Saturday & Sunday. 

#  pmset -g sched
Repeating power events:
  shutdown at 0:00AM weekends only
Scheduled power events:
 [0]  shutdown at 05/26/07 00:00:00 by Repeating

 

Energy Saver -> Options-> Schedule Repeating Weekends

Setting Repeating Events 


You can use the following syntax to set a repeating even...

pmset repeat type weekdays time
  • type - one of sleep, wake, poweron, shutdown, wakeorpoweron
  • weekdays - a subset of MTWRFSU 
  • time - hh:mm:ss
For example, to set startup at 7:00 AM on Monday, Wednesday and Friday.

pmset repeat wakeorpoweron MWF 7:00:00

Or if you want to set  startup on weekdays...

pmset repeat wakeorpoweron MTWRF 7:00:00

Or weekends...

pmset repeat wakeorpoweron SU 7:00:00

Or everyday...

pmset repeat wakeorpoweron MTWRFSU 7:00:00  

Setting an Event for a Specific Date & Time


In addition to setting event repeat on a day or days at a specific time, you can also specify that an even run on a specific date at a specific time.

The basic syntax is as follows...
 
pmset schedule type date+time
  • type - one of sleep, wake, poweron, shutdown, wakeorpoweron
  • time - "mm/dd/yy hh:mm:ss" (in 24 hour format; must be in quotes)
For example, you want to play a joke on April Fools Day and want to shutdown all your computers during the work time. So, I could use the following command...

# pmset schedule shutdown "04/01/2008 11:00:00"

And to check that it is scheduled...
 
# pmset -g sched
Scheduled power events:
 [0]  shutdown at 04/01/08 11:00:00


Then you also thought it would be a good idea to have the Mac's take a day off for Labor Day...
 
# pmset schedule sleep "09/01/2008 00:00:00"
# pmset schedule wake "09/02/2008 00:00:00"


So, now we have the following scheduled events...
 
# pmset -g sched
Scheduled power events:
 [0]  wake at 09/02/08 00:00:00
 [1]  sleep at 09/01/08 00:00:00
 [2]  shutdown at 04/01/08 11:00:00

Reset Energy Saver Settings to Default


Restores the system's energy settings to the default values...

# pmset -c 2 -b 1 -u 1


-c = Charger (wall power)
-b = Battery 
-u = UPS

Removing a Repeating Schedule


To remove a repeating schedule, use the following command...

pmset repeat cancel 

 

Removing an Event for a Specific Date & Time


In my example, I set the Mac's to shutdown for April Fools Day, but I re-thought it, and maybe my boss doesn't have the same sense of humor that I do and won't find the joke very funny.

So, I decided it might be better to remove this event.

So, I use the following command...

# pmset schedule cancel shutdown "04/01/2008 11:00:00"


And double-check the schedule to make sure I don't have to look for employment on April 2nd...

 # pmset -g sched Scheduled power events:

 [0]  wake at 09/02/08 00:00:00
 [1]  sleep at 09/01/08 00:00:00

Next, I decided that computers really are inanimate objects and don't need to rest for Labor Day, and could be put to work on some type of job. So, lets remove that event too.

# pmset schedule cancel sleep "09/01/08 00:00:00"
# pmset schedule cancel wake "09/02/08 00:00:00"


So, now I don't have any scheduled events... 

# pmset -g sched
No scheduled events.

Scenario


Ok, in our environment, we set the Mac's to startup at a certain time to make sure they run maintenance & are powered on for the students, staff or faculty that can't find the power button.

For example, we currently startup the Mac's at 6:30 AM everyday...
 
# pmset -g sched

Repeating power events:
  wakepoweron at 6:30AM every day
Scheduled power events:
 [0]  wakeorpoweron at 05/25/07 06:30:00 by Repeating
 [1]  wakeorpoweron at 05/26/07 06:30:00 by Repeating
 

We support Mac's across our campus, but a majority are located in our main Library, which has been going through major reconstruction and we have power outages that we need to make sure that the Mac's are properly shutdown and powered on for the users.

So, you can temporarily remove the repeating schedule using the following command via Apple Remote Desktop...

 Apple Remote Desktop - Remove pmset Repeating Schedule

Then schedule specific dates/times based on the dates/times of the power outage. 

For example, say, our Library was going to have a power outage or the power will sporadically come & go from noon for two days and it would be back on at noon. So, we could create a shutdown event that power off the Macs before the power issues occurs and then startup the Mac's after the power issues are to end.

For example...

 Apple Remote Desktop - Set Specific Date/Time Schedule

Then since the Mac should be power on, it will run maintenance, which in turn would re-establish the the power management repeating schedule with tools like radmind. Or if you aren't managing your file system routinely you could simply send another Apple Remote Deskop UNIX command to re-establish your repeating schedule.

Setting Multiple "Power On" & Power Off" Events



Currently, it appears that pmset will NOT allow you to set more than a pair of "power on" & "power off" repeating events.

For example...

# pmset repeat shutdown MTWRFSU 02:00:00 wakeorpoweron MTWRFSU 06:45:00

The above command would shutdown the Mac nightly at 2 AM in the morning and startup daily at 6:45 AM.

But,if you want to set multiple "power on" & "power off" events, you could specify a specific date/time and with a little scripting you could setup a schedule for a month.

# pmset schedule wakeorpoweron "06/07/2007 07:00:00"
# pmset schedule shutdown "06/07/2007 22:00:00"
# pmset schedule wakeorpoweron "06/07/2007 00:00:00"
# pmset schedule shutdown "06/07/2007 01:00:00"

Comments