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


Click here to return to the 'An improved shell script.' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An improved shell script.
Authored by: JiBB on Aug 18, '05 02:59:09AM
I found that the following shell script works, and it improves upon the original hint in two ways. It does not need to be run as root (or with admin privileges) because it uses the -force option of pmset to only effect the settings in memory. It also checks which set of settings should be used (Battery or AC charger) and reading and then restoring the original sleep time for that set of settings. E.g, if I have my display set to sleep after 5 minutes while on battery power and after 15 minutes while on AC power, this script will still restore these settings when done, unlike the original.

#! /bin/sh

# instasleep.sh
# Aug. 18, 2005, by JiBBerish@gmail.com
#
# Sets the display to sleep after one minute, then restores settings
# ..once sleep (presumeably) has begun.  Uses the force option, so
# ..doesn't need to be run as root.

orig_displaysleep=`pmset -g | grep displaysleep | awk '{print $2}'`
mode=`pmset -g | grep '\*$' | sed -e '/^AC/c\\
c' -e '/^Batt/c\\
b'`
echo "To restore orig. settings: pmset -mode displaysleep $orig_displaysleep"
echo "Sleeping in just a minute..."
pmset force -$mode displaysleep 1
sleep 70
pmset force -$mode displaysleep $orig_displaysleep
echo "Settings restored"


[ Reply to This | # ]
An improved shell script.
Authored by: JiBB on Aug 20, '05 02:22:10AM
Whoops, the line
echo "To restore orig. settings: pmset -mode displaysleep $orig_displaysleep"
should be
echo "To restore orig. settings: pmset -$mode displaysleep $orig_displaysleep"


[ Reply to This | # ]