Introduction

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 modify or set 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.

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.

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.

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

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

Scenerio

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...

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...

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.