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


Click here to return to the 'Simplified shell script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Simplified shell script
Authored by: TrumpetPower! on Nov 21, '05 12:27:23PM

For some time I’ve had a simple shell script called “zzz” that was a one-line osascript that just put the computer to sleep. Those of you familiar with OpenBSD (and probably others) will recognize why.

The fact that OS X is case-insensistive-but-preserving, combined with friendly’s hint, led me to update that one-liner. Save this somewhere in your $PATH and you'll be able to use zzz to sleep normally, and ZZZ (that’s all upper-case) to do a Safe Sleep.


#!/bin/sh

PATH=/bin:/sbin:/usr/bin:/usr/sbin;

if [ `basename ${0}` == "ZZZ" ]; then

    OriginalHibernateMode=`pmset -g | awk '/hibernatemode/ {print $2}'`;
    sudo -v;
    if sysctl vm.swapusage | grep -q 'encrypted'; then
        sudo sh -c "pmset -a hibernatemode 5; sleep 16; pmset -a hibernatemode ${OriginalHibernateMode}" &
    else
        sudo sh -c "pmset -a hibernatemode 1; sleep 16; pmset -a hibernatemode ${OriginalHibernateMode}" &
    fi
fi

osascript -e 'tell application "Finder" to sleep';

Now, a perfect accompaniment to this would be a hack that used the sleep / lid LED light as a power indicator. I’ve always been convinced that that light should be on steady and bright when the power is on; on steady but dim when running off battery; do the cycle / glow thing when sleeping; and be off when the computer is off. As it is now, you can’t tell the differece between a computer with the backlight off and one with the whole thing powered down, unless you try to wake it….

Cheers,

b&



[ Reply to This | # ]
Simplified shell script
Authored by: pecosbill on Sep 27, '06 02:04:33AM
This is great. Combined with this hint and the force hint above, I made a plain text file called Hibernate Now.command and put it on the Desktop. I change the permissions of that file so it would execute:
chmod u+x ~/Desktop/Hibernate\ Now.command
and put the following in it (I don't run secure VM):

#/bin/sh
# For added security:
PATH=/bin:/sbin:/usr/bin:/usr/sbin;

/bin/sh -c "pmset force -a hibernatemode 1; sleep 16; pmset force -a hibernatemode 3" &
/usr/bin/osascript -e 'tell application "Finder" to sleep';
Using the script above, you could set it up to work with either VM mode. The great part is it requires no password nor a set uid bit which makes me nervous when that UID is root.

---
Pecos Bill

[ Reply to This | # ]

A helper script to enter SafeSleep on demand
Authored by: digitol on Nov 21, '05 01:38:24PM

Ok basically similar to this post, just for lazy ppl, the suspendnow app may be a better solution.!!



[ Reply to This | # ]