A Mac sysadmin, documenting useful code, ideas, & guides.

AutoWake

· Read in about 2 min · (407 Words)
macos

Apple has some pretty nice energy savings options built into macOS. Most of these options are tucked nicely inside of the Energy Saver pane of System Preferences.

Energy Saver Panel

The above settings get written to the com.apple.AutoWake preference and looks like:

defaults read /Library/Preferences/SystemConfiguration/com.apple.AutoWake
{
    RepeatingPowerOff =     {
        eventtype = shutdown;
        time = 1020;
        weekdays = 127;
    };
    RepeatingPowerOn =     {
        eventtype = wakepoweron;
        time = 420;
        weekdays = 31;
    };
}

Weekdays

Some of these values are a bit opaque once they are written to the preferences domain. For example, when you set the Every Day option in the above screenshot this value is written in the weekdays key with a value of 127. So what does that value actually refer to? Each day gets a value starting from one that doubles with each passing day.

Weekdays values

  1 - Monday
  2 - Tuesday
  4 - Wednesday
  8 - Thursday
  16 - Friday
  32 - Saturday
  64 - Sunday

To select every day of the week you add all of the values together: 1+2+4+8+16+32+64 = 127. While weekdays would be: 1+2+4+8+16 = 31. The math is quite simple but easy to forget that this specific aspect of the system starts the day on Monday.

Time

The time value is configured as time after 00:00, or midnight, in seconds. Examples below:

4 am
  60m x 4h = 240s

1:30 pm
  60m x 13.5h = 810s

5:00 pm
  60m x 17h = 1020s

Profile

If you have gotten this far you might be wondering why any of the information above matters? If you have ever needed to create a configuration profile for Energy Saver, understanding these values allow you to customize the options without having to use a GUI like Profile Manager.

<key>com.apple.EnergySaver.desktop.Schedule</key>
<dict>
	<key>RepeatingPowerOff</key>
	<dict>
		<key>eventtype</key>
		<string>shutdown</string>
		<key>time</key>
		<integer>1200</integer>
		<key>weekdays</key>
		<integer>127</integer>
	</dict>
	<key>RepeatingPowerOn</key>
	<dict>
		<key>eventtype</key>
		<string>wakepoweron</string>
		<key>time</key>
		<integer>420</integer>
		<key>weekdays</key>
		<integer>31</integer>
	</dict>
</dict>

For a full profile example check out Nick McSpadden’s EnergySaver.mobileconfig. Note: Nick’s profile contains other energy saver options that you will likely want to include and/or modify.

Random

The RepeatingPowerOff > eventtype string actually accepts three types: restart, sleep, and shutdown. Unfortunately the system will only read one RepeatingPowerOff dict. That means you are unable to get creative and say restart Monday-Friday at 8pm and shutdown Saturday-Sunday at 3pm.


Links:
OS X Yosemite: Schedule a time for your Mac to turn on or off or go to sleep,
OS X: Setting a startup or shut down time,

Comments