One of the things I routinely do is work on end users machines. Sometimes this includes needing the user to sign …. while I do whatever is that needs done … troubleshoot, transfer data, etc.
It’s incredibly frustrating for a user to sign into their account and then leave while I start working only to have the computer go to sleep and get the screen-lock and prompt for the users password. I can manually changes the power settings, but to often I forget and have always meant to write a short script to turn the screen-lock, screen saver, and sleep settings off, and then back on when I’m done.
Today, I wrote a couple. One to turn the settings off, and then one to turn them back on when I’m done working and the user picks up their computer. These worked in my testing, you should do the same before using them on a user’s machine.
Turn Power & Sleep Settings Off
#!/bin/bash #tested on 10.11 #turn display sleep, computer sleep and hard drive sleep off pmset -c displaysleep 0 sleep 0 disksleep 0 #turn off ask for password and screen saver sudo -u $SUDO_USER defaults write /Users/$SUDO_USER/Library/Preferences/com.apple.screensaver askForPassword 0 sudo -u $SUDO_USER defaults write /Users/$SUDO_USER/Library/Preferences/ByHost/com.apple.screensaver idleTime 0
Turn Power & Sleep Settings On
#!/bin/bash #tested on 10.11 #turn display sleep to one hour. change sleep and disksleep if you prefer pmset -c displaysleep 60 sleep 0 disksleep 0 #turn screen lock on, ask for password after 5 minutes, turn screen saver on and set to 20 minutes sudo -u $SUDO_USER defaults write /Users/$SUDO_USER/Library/Preferences/com.apple.screensaver askForPassword 1 sudo -u $SUDO_USER defaults write /Users/$SUDO_USER/Library/Preferences/com.apple.screensaver askForPasswordDelay 300 sudo -u $SUDO_USER defaults write /Users/$SUDO_USER/Library/Preferences/ByHost/com.apple.screensaver idleTime 900
I took it a bit further and put both into a script with an interactive prompt … asking which would you like to do. Granted .. I’m assuming a couple of things. You’re logged into the user account you want to work on, you’re on AC power, and you type either “on” or “off” at the prompt. You can always change the script and the power settings to your liking.
Interactive: Turn Power & Sleep Settings On
#!/bin/bash #version 1.1 [ "$UID" -eq 0 ] || exec sudo bash "$0" "$@" echo "Do you want to set power & sleep settings on or off?: " read powersettings if [[ $powersettings == off ]]; then echo "Turning power settings off" pmset -c displaysleep 0 sleep 0 disksleep 0 sudo -u $SUDO_USER defaults write /Users/$SUDO_USER/Library/Preferences/com.apple.screensaver askForPassword 0 sudo -u $SUDO_USER defaults write /Users/$SUDO_USER/Library/Preferences/ByHost/com.apple.screensaver idleTime 0 elif [[ $powersettings == on ]]; then echo "Turning power settings on" pmset -c displaysleep 60 sleep 0 disksleep 0 sudo -u $SUDO_USER defaults write /Users/$SUDO_USER/Library/Preferences/com.apple.screensaver askForPassword 1 sudo -u $SUDO_USER defaults write /Users/$SUDO_USER/Library/Preferences/com.apple.screensaver askForPasswordDelay 300 sudo -u $SUDO_USER defaults write /Users/$SUDO_USER/Library/Preferences/ByHost/com.apple.screensaver idleTime 900 else echo "No choice selected" fi sleep 1 Killall Terminal