A helper script to enter SafeSleep on demand

Nov 21, '05 06:39:00AM

Contributed by: friendy

If you're using 10.4.3, you may have already tried out enabling Safe Sleep on your computer using the tips from Andrew Escobar's blog. I found it works great on my Powerbook G4 867, but I didn't want to have to keep using the Terminal to switch it from hibernatemode 3 (computer uses regular sleep, only Safe Sleeps in extreme situations) to hibernatemode 1 (goes straight into Safe Sleep).

So I wrote an AppleScript application that flips the machine to mode 1, sleeps the machine, then turns it back to mode 3 upon awaking, so that I can use Safe Sleep on demand.

The code is as follows:

do shell script "/usr/bin/sudo -k;/usr/bin/sudo /usr/bin/pmset -a hibernatemode 1; /usr/bin/sudo -k" password ¬ 
 "_password_" with administrator privileges
ignoring application responses
  tell application "Finder" to sleep
  do shell script "(/bin/sleep 15 && /usr/bin/sudo -k && ¬
   /usr/bin/sudo /usr/bin/pmset -a hibernatemode 3 ¬
   && /usr/bin/sudo -k) &> /dev/null &" password ¬
   "_password_" with administrator privileges
end ignoring

Save this as a Run Only application with no Startup Screen, and you've got a great Dock item to use when swapping a battery with no power cord (or whatever).

As an added bonus, save it as an Application Bundle type (in the Save dialog), and then edit the Info.plist file you'll find inside the application's package, and add these lines:
<key>LSUIElement</key>
<string>1</string>
Now you have a handy faceless application, suitable for use with your favorite keystroke launcher.

Things to adjust: [robg adds: I haven't tested this one. A very recent hint on Safe Sleep links to Andrew's instructions as well...]

Comments (14)


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