User:James.tantalo/Sandbox

In computing, pmset is a command line utility to manipulate power management settings under the Darwin and Mac OS X operating systems. It can assign sleep settings, schedule sleep and wake times, and display power information.

History
The pmset utility first appeared in Darwin 6.0.1 and OS X 10.2 "Jaguar". It has been updated periodically since its introduction, and is still available as of Darwin 9.4 and OS X 10.5.4 "Leopard".

Behavior
The utility sets or lists power management settings. Some of the functionality provided by the utility is available through the GUI interface of the Energy Saver preference pane. However, pmset allows for greater flexibility and access to several options not available in the GUI.

The utility can set different power management settings depending on usage scenario. Different settings can be applied for when the machine is running off a charger, battery, UPS, or all three. The appropriate flags are as follows:


 * -c (charger), adjust settings used while connected to a charger
 * -b (battery), adjust settings used when running off a battery
 * -u (UPS), adjust settings used when running off a UPS
 * -a (all, default) adjust settings for all scenarios

Additional arguments be supplied when assigning any power management settings. Power management arguments are discussed in greater detail below. When invoking the command, only specified arguments modify power management options. Any arguments already set will be unmodified by pmset unless those arguments are specifically included.

The utility can schedule wake, sleep, power on or power off events. Events can be recurring based on arbitrary weekday and time combinations, or scheduled for future dates and times. The syntax for scheduling an event is as follows:


 * <tt>pmset [repeat, schedule] [sleep, wake, poweron, shutdown, wakeorpoweron] [<MTWRFSU> <date/time>] </tt>

The utility is limited to setting one recurring and one scheduled event.

The get flag displays information about the current power management configuration, or a log of recent activity. If no additional arguments are supplied the flag will only display current settings. Additional get arguments are discussed in greater detail below. The get flag is as follows:


 * <tt>-g</tt> get, list current power management settings

The utility is also able to configure hibernation and safe sleep options, and change Energy Saver profiles.

Power Management Settings
The <tt>pmset</tt> utility recognizes the following arguments. Arguments can be passed in serial form in any order. Any bad syntax or unrecognized argument will cause the entire command to fail, resulting in an error message and brief help screen. Power management settings can only be changed by a privileged user.


 * <tt>displaysleep</tt> display sleep timer in minutes, 0 to disable display sleep
 * <tt>disksleep</tt> disk spindown timer in minutes, 0 to disable disk sleep
 * <tt>sleep</tt> system sleep timer in minutes, 0 to disable sleep
 * <tt>womp</tt> wake on "magic" Ethernet packet, 1 to enable or 0 to disable
 * <tt>ring</tt> wake on modem ring, 1 to enable or 0 to disable
 * <tt>autorestart</tt> automatic restart after loss of power, 1 to enable or 0 to disable
 * <tt>dps</tt> dynamically change processor speed based on load, 1 to enable or 0 to disable
 * <tt>reduce</tt> permanently reduce processor speed, 1 to enable or 0 to disable
 * <tt>powerbutton</tt> put the machine to sleep when the power button pressed in stead of shutting it down, 1 to enable or 0 to disable
 * <tt>lidwake</tt> (laptop only) wake the machine when the laptop lid is opened, 1 to enable or 0 to disable
 * <tt>acwake</tt> (laptop only) wake the machine when the power source is changed, such as when AC power is removed and the machine switches to battery power, 1 to enable or 0 to disable
 * <tt>lessbright</tt> (laptop only) slightly turn down display brightness when switching to a specified power source, 1 to enable or 0 to disable
 * <tt>halfdim</tt> display sleep will use an intermediate half-brightness state between full brightness and fully off, 1 to enable or 0 to disable
 * <tt>sms</tt> (supported laptops only) use Sudden Motion Sensor to park disk heads on sudden changes in G force, 1 to enable or 0 to disable
 * <tt>haltlevel</tt> (UPS only) UPS charge in percentage, shutdown the machine when UPS reaches a specified charge level
 * <tt>haltafter</tt> (UPS only) UPS charge in minutes, shutdown machine after drawing on UPS for specified number of minutes
 * <tt>haltremain</tt> (UPS only) UPS charge in minutes, shutdown machine when specified time remains on UPS
 * <tt>ttyskeepawake</tt> prevent idle system sleep when any tty (such as a remote login session) is active; a tty is inactive only when its idle time exceeds the system sleep timer, 1 to enable or 0 to disable

Settings may be adjusted independently for circumstances where the machine is attached to a charger, when running off a battery (in the case of a laptop), or when running off a UPS (if available). Settings can also be adjusted for all four scenarios simultaneously; this is the default option, for when no usage flag is specified. Power management options can be specified for different profiles by appending <tt>-c</tt> (charger), <tt>-b</tt> (battery), <tt>-u</tt> (UPS) or <tt>-a</tt> (all) flags. The following example will set the machine to sleep after 10 minutes and sleep the display after five minutes, but only when powered by the battery.


 * <tt>pmset -b sleep 10 displaysleep 5</tt>

The following command will assign slightly different power management settings for circumstances where the machine is powered by the charger. Here, the machine is set to sleep after 30 minutes and the display is set to never sleep, but only when set by the charger. Issuing both commands will not interfere with each other.


 * <tt>pmset -c sleep 30 displaysleep 0</tt>

Arguments can be entered in serial form to set or modify several power management parameters with one command. The following command will set the machine to never sleep (<tt>sleep 0), enable the Sudden Motion Sensor (<tt>sms 1</tt>), set the display to sleep after 20 minutes (<tt>displaysleep 20</tt>), disable processor speed reduction (<tt>reduce 0</tt>), enable intermediate display dimness (<tt>halfdim 1</tt>), enable the machine to wake when the lid is opened (<tt>lidwake 1</tt>), prevent the system from seeping when a tty session (such as SSH) is active (<tt>ttyskeepawake 1</tt>), disable waking the machine when the AC adapter is inserted (<tt>acwake 0</tt>), disable an automatic restart after power is removed and restored (<tt>autorestart 0</tt>), enable dynamic change of processor speed based on system load (<tt>dps 1</tt>), enable wake on modem ring (<tt>ring 1</tt>), enable wake on receipt of "magic" Ethernet packet (<tt>womp 1</tt>), and disable hard disk sleep (<tt>disksleep 0</tt>):


 * <tt>pmset sleep 0 sms 1 displaysleep 20 reduce 0 halfdim 1 lidwake 1 ttyskeepawake 1 acwake 0 autorestart 0 dps 1 ring 1 womp 1 disksleep 0</tt>

Because the above example did not include a usage flag, the settings specified will apply to all usage scenarios. Subsequent commands that do specify a usage flag will only affect settings for that usage scenario. For instance, <tt>pmset -b sleep 10</tt> will cause the machine to sleep after 10 minutes, but only when the battery is attached. All other settings will apply when the battery is attached, and all settings in the above example will apply when a charger or UPS is attached.

At least as of Darwin 9.4 and OS X 10.5.4 "Leopard", all changes made through <tt>pmset</tt> are saved in a persistent preferences file at <tt>/Library/Preferences/SystemConfiguration/com.apple.PowerManagement.plist</tt>. This file can be modified manually using the <tt>defaults</tt> command, but those changes will not be taken up immediately by the power management system. Manual edits of <tt>com.apple.PowerManagement.plist</tt> also stand the risk of being overwritten. The command <tt>pmset touch</tt> will reread existing settings from disk and apply them to the system.

Schedule Settings
The <tt>pmset</tt> command is able to schedule system sleep, shutdown, wakeup or power on events. The <tt>schedule</tt> argument is for setting up one-time power events, and <tt>repeat</tt> is for setting up daily or weekly events. A limitation in <tt>pmset</tt> prevents setting more than one scheduled or repeating event. To set a pair of repeating events, for instance an event to power on and an event to power off, use the Energy Saver preference pane. Scheduling of events can only be done by a privileged user.

The <tt>schedule</tt> argument recognizes the following additional arguments:


 * type; one of <tt>sleep</tt>, <tt>wake</tt>, <tt>poweron</tt>, <tt>shutdown</tt> or <tt>wakeorpoweron</tt>
 * date and time (schedule only); in the format <tt>"MM/dd/yy HH:mm:ss"</tt>; must be in 24 hour format, must be in quotes
 * time (repeat only); in the format <tt>HH:mm:ss</tt>; must be in 24 format, but does not have to be in quotes
 * weekdays; a subset of <tt>MTWRFSU</tt> such as <tt>M</tt> or <tt>MTWRF</tt> are valid, as are strings <tt>weekdays</tt>, <tt>weekends</tt>, and <tt>everyday</tt>
 * owner; a string describing the person or program who is scheduling the power event (optional)

The utility can be very unforgiving of improper syntax. Any errors in syntax will cause the command to fail and will display a brief help message. The syntax for a scheduled event is as follows:


 * <tt>pmset schedule [sleep, wake, poweron, shutdown, wakeorpoweron] "MM/dd/yy HH:mm:ss"</tt>

Only one type of event (sleep, wake, et cetera) can be specified, and the date chosen must be in the future. The utility expects to be able to store this information in the PMU, and so may not work reliably on non-Apple hardware. The date and time string must be enclosed in quotation marks.

The syntax for a repeating event is as follows:


 * <tt>pmset repeat [sleep, wake, poweron, shutdown, wakeorpoweron] [MTWRFSU, weekdays, weekends, everyday] HH:mm:ss</tt>

Like scheduled events, only one type of repeating event (sleep, wake, et cetera) can be specified. Any combination of weekdays can be chosen, as well as the strings "weekdays", "weekends", or "everyday". A time must be specified.

Scheduled wake, sleep and power events are stored in a persistent preferences file in <tt>/Library/Preferences/SystemConfiguration/com.apple.AutoWake.plist</tt>. This file can be manually edited using the <tt>defaults</tt> command, but any changes so made stand a serious risk of being overwritten. Also, such edits will not be immediately taken up by the system.

List Options
The list flag, <tt>-g</tt>, displays information about the current power configuration. The flag alone, with no additional arguments, will display current power management settings. Additional arguments will display more specific information. The get functions of <tt>pmset</tt> do not require privileged access. The utility recognizes the following arguments:


 * <tt>live</tt> like the default option, displays the settings currently in use
 * <tt>custom</tt> will display custom settings for all power sources, although these settings may not currently be in use
 * <tt>cap</tt> capabilities, display which power management features the machine supports
 * <tt>sched</tt> schedule, display scheduled startup, wake, shutdown and sleep events
 * <tt>ups</tt> will display UPS emergency thresholds
 * <tt>ps</tt> power source, display status of connected batteries and UPSs
 * <tt>pslog</tt> display an ongoing log of power source state
 * <tt>rawlog</tt> display an ongoing log of power source state as read directly from battery
 * <tt>profiles</tt>

Only one get argument can be passed to <tt>pmset</tt>, and it must be preceded by the get flag. For instance, to display scheduled events, type <tt>pmset -g sched</tt>. The utility will not return an error is more than one get argument is provided, but all other than the first will be ignored.

Sample usage
The following examples demonstrate the output of the <tt>pmset</tt> command on an Apple PowerBook G4 running OS X 10.5.4 "Leopard".

The following example will apply only to laptops when powered by the battery. It will set the machine to sleep after 5 minutes of inactivity, put the display to sleep after 2 minutes, and spin down the hard disk after 3 minutes. Only privileged users can issue this command. If the command is issued successfully and is without syntax errors, <tt>pmset</tt> will exit silently with an exit code of 0. To verify that the system took the new configuration, issue the command <tt>pmset -g</tt>.

The following example will apply only to machines being powered by a UPS. It will set the machine to preform an emergency shutdown when 5 percent battery remains on the UPS, or 5 minutes estimated draw time remains, whichever comes first. Only privileged users can issue this command. If the command is issued successfully and is without syntax errors, <tt>pmset</tt> will exit silently with an exit code of 0. To verify that the system took the new configuration, issue the command <tt>pmset -g</tt>.

The following example will apply for all usage scenarios. It will set the machine to wake on receipt of a "magic" Ethernet packet, wake if the the modem detects a ring, and prevent the system from sleeping if a tty session is active. Only privileged users can issue this command. If the command is issued successfully and is without syntax errors, <tt>pmset</tt> will exit silently with an exit code of 0. To verify that the system took the new configuration, issue the command <tt>pmset -g</tt>.

The following example sets a one-time scheduled power event. The machine will be set to shutdown 01/10/2009 at 10:00 PM. Only privileged users can issue this command. If the command is issued successfully and is without syntax errors, <tt>pmset</tt> will exit silently with an exit code of 0. To verify that the system took the new configuration, issue the command <tt>pmset -g sched</tt>.

The following example sets a repeating power event. The machine will wake or power on every weekday at 8:00 AM. Only privileged users can issue this command. If the command is issued successfully and is without syntax errors, <tt>pmset</tt> will exit silently with an exit code of 0. To verify that the system took the new configuration, issue the command <tt>pmset -g sched</tt>.

Here, example output from <tt>pmset -g</tt>. At the time, the machine was being powered by the charger, while simultaneously charging the battery. The command prints the current configuration.

Here, example output from <tt>pmset -g sched</tt>. In this example, the machine has already been configured for a repeating event to start or wake up every weekday at 8:00 AM. The command prints the repeating event; note that the next such occurrence appears as a scheduled power event.