Another script to set energy saver settings via pmset

May 05, '04 09:17:00AM

Contributed by: Anonymous

I run a server on my computer so I can't let it go to sleep or turn off. I usually just go to System Preferences and turn off the monitor after one minute when I go to sleep, but then i discovered pmset. I wrote a shell script that allows you to set the computer for daytime, nighttime, or sleep mode.

Daytime sets the monitor to dim at 20 minutes, the hard drive to spin down in 10 minutes, the volume to 4, and processor speed to automatic. Nighttime sets the monitor to dim at 1 minute, the hard drive to spin down in 1 min, the volume to mute, and the processor speed to reduced. Sleep sets the computer to sleep in 1 min, and only wakes on a magic packet.

Read the rest of the hint for the script...

[robg adds: This script seems to work as described ... and there are a few more pmset hints here; it's a very handy command...]

The script:


#!/bin/bash
# pmset script

function usage
{
 echo "Usage: [-h | --help] | [ [-n --night] [-d --day] [-s --sleep] ]"
}

if [ $(id -u) = "0" ]; then
echo
else
 usage
 echo "Must be run as root..."
 exit 1
fi

mode=

 case $1 in
   -n | --night )          mode=1
     ;;
   -d | --day )            mode=2
     ;;
   -s | --sleep )          mode=3
     ;;
   -h | --help )           usage
     exit
     ;;
   * )                     usage
     exit 1
 esac

if [ "$mode" = "1" ]; then
    pmset womp 1 dps 0 dim 1 reduce 1 autorestart 1 spindown 1 sleep 0 acwake 0 ring 0;
    osascript -e 'tell application "System Events" to set volume 0'
    osascript -e 'tell application "iChat" to set status to away
 tell application "iChat" to set status message to "Away"'
    echo "$HOSTNAME set to nighttime mode";
fi
if [ "$mode" = "2" ]; then
    pmset womp 1 dps 1 dim 20 reduce 0 autorestart 1 spindown 10 sleep 0 acwake 0 ring 1
 osascript -e 'tell application "System Events" to set volume 4'
    echo "$HOSTNAME set to daytime mode"
fi
if [ "$mode" = "3" ]; then
    pmset womp 0 dps 0 dim 1 reduce 1 autorestart 1 spindown 1 sleep 1 acwake 0 ring 0
    echo "$HOSTNAME set to sleep/dormant mode"
fi

exit

Comments (7)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040501162832325