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


Click here to return to the '10.6: Fix sleep problems with SleepWatcher' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.6: Fix sleep problems with SleepWatcher
Authored by: hickscorp on Nov 30, '11 04:29:42PM
Hello, i have been using this hack for a lot of time now, and i just realized that my .sleep / .wakeup scripts could help some of you. My sleep script takes care of two issues i had with my Mac (Even with Lion). - A lot of my peripherals are connected to my computer via Bluetooth. When my Mac goes to sleep, i want to avoid it being woke up by my cat playing with the mouse or walking on the keyboard. That's why i am using blueutil tools in conjunction with the tools described here. However, i don't want my bluetooth peripherals to be connected upon wake if they were not connected before sleeping. That's why my script writes the status of bluetooth radio in a file (.oldBlueStatus) before sleeping, so it is able to know if it has to re-activate it upon waking up or not. - If you have a software RAID, ejecting the volumes mounted in /Volumes isn't sufficient to fully eject the physical disks on which the strips / mirrors are located. Therefore, i use the appleRAID command to take care of that. You may notice that i'm testing for "/Volumes/Data" before ejecting the volumes. This is specific to my set up: in my Macbook Pro i have a SSD for my system, and a mechanical HDD for my data. My whole home sits on the mechanical, so it has to stay mounted whatever happens, hence the test on "/Volumes/Data". Below are the scripts i wrote to take care of the jobs. .sleep #!/bin/bash DF="/bin/df" CAT="/bin/cat" LG="/usr/bin/logger" AWK="/usr/bin/awk" CUT="/usr/bin/cut" TR="/usr/bin/tr" DU="/usr/sbin/diskutil" BU="/usr/local/bin/blueutil" # Growls one argument. function growl { osascript <<-EOF tell application id "com.Growl.GrowlHelperApp" to notify with name "SleepWatcherEvent" application name "Sleep Watcher" title "Sleep Watcher" description "&#36;1" EOF } # Detach from any removable media. This would also work: # osascript -e 'tell application "Finder" to eject the disks' for vol in `&#36;DF | &#36;AWK '{print &#36;1":"&#36;6}'`; do mp=&#36;{vol##*:} if [ "&#36;{mp%/*}" == "/Volumes" ] &amp;&amp; [ "&#36;mp" != "/Volumes/Data" ]; then &#36;LG "Detaching from &#36;{vol##*:}" echo &#36;{vol##*:} &#36;mp hdiutil detach &#36;{vol##*:} 2>/dev/null; fi done # Detach from any RAID container set. for vol in `$DU appleRAID list | grep disk | $CUT -d\ -f3 | $CUT -c1-5 | sort | uniq`; do $LG "Detaching from $vol" hdiutil detach $vol > /dev/null 2>/dev/null; done # Disable BlueTooth. OldBlueStatus=`$BU status | $CUT -d\ -f2 | $TR -d "\n"` echo $OldBlueStatus > .oldBlueStatus if [ "$OldBlueStatus" = "on" ]; then $LG "Disabling Bluetooth..." $BU off fi .wakeup: #!/bin/bash DF="/bin/df" CAT="/bin/cat" LG="/usr/bin/logger" AWK="/usr/bin/awk" CUT="/usr/bin/cut" TR="/usr/bin/tr" DU="/usr/sbin/diskutil" BU="/usr/local/bin/blueutil" # Growls one argument. function growl { osascript <<-EOF tell application id "com.Growl.GrowlHelperApp" to notify with name "SleepWatcherEvent" application name "Sleep Watcher" title "Sleep Watcher" description "&#36;1" EOF } OldBlueStatus=`&#36;CAT .oldBlueStatus | &#36;TR -d "&#92;n"` if [ "&#36;OldBlueStatus" = "on" ]; then &#36;LG "Enabling Bluetooth..." &#36;BU on fi</code> i hope this will help. Pierre. P.S.: Sorry for the bad english. It's late here.

[ Reply to This | # ]