System Preferences - Energy Saver

monaronyc
Contributor

Hi Folks!

Upper management asked if I could create a script to manage the power settings for our iMacs. The built in config profile settings in the JSS don't seem to match and they couldn't get it to work to their specs. So I came up with a script to set the Energy Saver prefs in System Preferences the way they'd like them set for now. But having a little trouble. When I push it via Casper, sometimes it works and sometimes it doesn't. But when I run the script from the local machine, works every time. I was wondering if there needs to be a little more 'logic' to the script for it to work in a Casper policy. If anyone can see. Here's what I have scripted with screenshot of what they want:

#!/bin/bash

# Sets Turn Display Off after... Never

systemsetup -setsleep never

# Sets Prevent computer from sleeping automatically

systemsetup -setcomputersleep never

# Sets Put Hard Disks to Sleep when possible off

pmset -c disksleep 0

# Sets Wake for network acccess to on

systemsetup -setwakeonnetworkaccess on

# sets Startup automatically after a power failure

systemsetup -setrestartpowerfailure on

# turns off Power Nap in Energy Saver

pmset -c darkwakes 0

# Turns on the Schedule power on weekdays at 12am in Schedule button

pmset repeat wakeorpoweron weekdays 00:00:00



exit 0

7b2e5cb624024addbdf0a702d36172c0

5 REPLIES 5

alexthegeekiest
New Contributor

Thanks for the script. I was able to run with Jamf and it did exactly what you indicated!

Scotty
Contributor

Here's what I do for this, in case it helps anyone else... ( our screen lock policy)

  1. Password required instantly after screen wake, screen saver, sleep (via Security & Privacy profile)
  2. Screen Saver set to a hard 20min - this is the only real way to force the machine to lock consistently (must be Apples preset time options)
  3. Power Management set to sleep the Displays at 20 mins via a script. Now, since the user can always change this on their own and I dont want to enforce the other options in power management, and even with a profile the display sleep time is user adjustable, we do it with with a script, a EA and a smart group. 3a. EA to find all machine with a current display sleep time over 20min (power or battery) 3b. Smart Group to collect machines with values over 20mins 3c. Policy to run a script to set the display sleep accordingly.

So, if a user sets a time over 20mins, Jamf sets it back to 20/5 (power/battery) at some point, they can run higher for a while but useally in 1 day it kicks back. This lets them change it anywhere from 0-20, but if they go over Jamf will eventually catch them. Yes the stubborn user can avoid this changing it daily, but they cant avoid the 20min screen saver. So really its just a power saving thing. Keeps the screens off as much as possible.

Heres our EA

#!/bin/sh
echo "<result>`/usr/bin/pmset -g 2>&1 | grep displaysleep | awk '{print $2}'`</result>"

Heres our Display Sleep (use parameters for the values)

#!/bin/bash
#set Display sleep Battery
pmset -b displaysleep $4
#set Display sleep power Adapter
pmset -c displaysleep $5
#set Display sleep ups
pmset -u displaysleep $6

Not sure if this is KISS or not with all the layers, but we try...

OptimaX
New Contributor

I have scheduled to make all iMacs at my office come on at 6am in the mornings on weekdays (and going off at 7pm). I don't really want to mess up this schedule, but I want a one-time exception to have them NOT come on on a specific day (Bank Holiday). Any suggestions?

mwilkerson
New Contributor III

@ScottSimmons Re: #3. I was recently playing around with a configuration profile to control display sleep on portables and while it's true that a user can go in after the fact and change the value set in the config profile, it doesn't stay for long. There is a time frame where the config profile is enforced and the value changes back. Sounds like what you're doing manually with the script. FYI.

AdamCraig
Contributor III

@ScottSimmons thanks for your post! It was very helpful. Your EA displays whichever sleep setting is currently active so will vary based on if User is on battery or power adaptor when inventory is run. I set up this EA to display of whichever one is greater.

#!/bin/bash
## sleep time EA

displaySleepBatt=`pmset -g custom | awk '/Battery Power/{f=1} /disksleep/{f=0;print} f' | grep "displaysleep" | awk '{print $2'}`
displaySleepPower=`pmset -g custom | awk '/AC Power/{f=1} /disksleep/{f=0;print} f' | grep "displaysleep" | awk '{print $2'}`

## determine if battery or power adaptor setting is greater
if (( $displaySleepBatt > $displaySleepPower )) ; then
    greater=$displaySleepBatt
else
    greater=$displaySleepPower
fi

echo "<result>$greater</result>"
exit 0