Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Another script to set energy saver settings via pmset UNIX
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
    •    
  • Currently 2.33 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (3 votes cast)
 
[12,873 views]  

Another script to set energy saver settings via pmset | 7 comments | Create New Account
Click here to return to the 'Another script to set energy saver settings via pmset' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Another script to set energy saver settings via pmset
Authored by: jeffulri on May 05, '04 01:49:33PM

Since this script sets iChat status to away in night time mode, you'll probably want it to also turn it to available in day time mode. So this will do that:

#!/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'
osascript -e 'tell application "iChat" to set status to available
tell application "iChat" to set status message to "Available"'
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

PS: I'm having what I'd like to call issues with the way this script is setting sound levels. It isn't actually muting the system volume in night time mode (I can still hear iTunes playing, but the system volume slider is at 0%), nor is it setting system sound volume to 100% (I'd prefer 75% actually) in day time mode. I'm not familiar enough with Applescript to KNOW how to address this issue, but fiddling with the number after "tell application "System Events" to set volume" doesn't yield results that I'd expect. Presumably, the variable range is 0 = no volume, 100 = full volume but 100 only sets my system volume to 50% -- as does 200 (I was just guessing here -- 75 too for that matter [Grin]). Any help on this issue would be greatly appreciated!



[ Reply to This | # ]
Stumped
Authored by: 5chm31din6 on May 06, '04 12:02:52AM
Can't get it to work for me. I called the script, "ampm" but it won't run. I try running it thusly:

sudo ./ampm and I get:

sudo: ./ampm: command not found

I dunno what the deal is. I've tried it with sudo, without, etc. No dice. Any ideas?

---
Signature, schmignature.

[ Reply to This | # ]

Stumped
Authored by: 5chm31din6 on May 06, '04 12:28:47AM
Whoops! I forgot to mention I also tried running it without the ./, and every other way you can think of. Nada. Zip. 86. Air. Goose eggs. Ace. No joy.

---
Signature, schmignature.

[ Reply to This | # ]

Stumped
Authored by: mathurak on May 06, '04 11:26:57PM

Is your script set to be executable?

chmod +x ampm



[ Reply to This | # ]
Stumped
Authored by: 5chm31din6 on May 07, '04 10:24:31AM
That did the trick! Thanks!

---
Signature, schmignature.

[ Reply to This | # ]

Cronscripts
Authored by: psychozz on May 07, '04 04:14:21PM
I have a server that acts like a firewall and a router and it's also my apple share server. So I was thinking of making two scripts, one that set the server to day mode and another one to set it to night mode, and add these scripts to the systems crontab

Will this work?

Example (/etc/crontab):

0     7       *       *       *       root    /Library/Scripts/pmset_day
5     0       *       *       *       root    /Library/Scripts/pmset_night
Or if you stay up late on fridays and saturdays it would look like this:

0     7       *       *       1-5       root    /Library/Scripts/pmset_day
5     0       *       *       1-5       root    /Library/Scripts/pmset_night
0     9       *       *       6-7       root    /Library/Scripts/pmset_day
0     3       *       *       6-7       root    /Library/Scripts/pmset_night
You cannot put a sleep script in here because cronscripts don't run if the computer is asleep.

[ Reply to This | # ]
Remove?
Authored by: Superboy on Jul 06, '04 08:18:17PM

Hi
Could someone tell me how to remove the pmset thing...?

Thanks!
Elijah



[ Reply to This | # ]