|
|
10.6: Fix sleep problems with SleepWatcher
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 "$1"
EOF
}
# Detach from any removable media. This would also work:
# osascript -e 'tell application "Finder" to eject the disks'
for vol in `$DF | $AWK '{print $1":"$6}'`; do
mp=${vol##*:}
if [ "${mp%/*}" == "/Volumes" ] && [ "$mp" != "/Volumes/Data" ]; then
$LG "Detaching from ${vol##*:}"
echo ${vol##*:} $mp
hdiutil detach ${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 "$1"
EOF
}
OldBlueStatus=`$CAT .oldBlueStatus | $TR -d "\n"`
if [ "$OldBlueStatus" = "on" ]; then
$LG "Enabling Bluetooth..."
$BU on
fi</code>
i hope this will help.
Pierre.
P.S.: Sorry for the bad english. It's late here.
|
SearchFrom our Sponsor...Latest Mountain Lion HintsWhat's New:HintsNo new hintsComments last 2 daysLinks last 2 weeksNo recent new linksWhat's New in the Forums?
Hints by TopicNews from Macworld
From Our Sponsors |
|
Copyright © 2014 IDG Consumer & SMB (Privacy Policy) Contact Us All trademarks and copyrights on this page are owned by their respective owners. |
Visit other IDG sites: |
|
|
|
Created this page in 0.09 seconds |
|