Jump to content

Sleep results in poweroff when a USB Drive is mounted


  • Please log in to reply
1 reply to this topic

#1
ApexDE

ApexDE

    InsanelyMac Geek

  • Members
  • PipPipPipPip
  • 217 posts

I have my system perfectly running except for one thing: when i forget to unmount and remove a USB Stick before i put the system to sleep, the computer powers off when i try to put the system to sleep. It is almost "instant power off" when i try to sleep the system, even no sleep-image is written to the harddrive.


I am using ML, but it happened with Lion also.


For now, i am using Applescript and sleepwatcher to unmount USB Drives prior to sleep. But i would like to apply a proper fix via DSDT or whatever would be needed. As the system immediately powers off, i have no log-entries or kernel messages :(


Any Ideas what that might be?


#2
stefan42

stefan42

    InsanelyMac Protégé

  • Members
  • Pip
  • 3 posts
Hi,

I've got this little script wrapped into an Platypus app. It is un-mounting my SMB network drives, and local USB drives which run my Time Machine.
It sends the Mac then to sleep.
You can safely unplug the USB devices, while the Mac is sleeping or just when the script prompts you.
This powers down the USB devices physically.

Please plug in the USBs in before you wake up your Mac.
Then the remaining part of the script is automatically re-mounting all physically connected USB drives again and the SMB drives in your list. I played with the OSX automounter extensively and gave it up to handle the SMB automount in the correct UNIX way. Apple's automounter is simply too buggy.
I have also a good USB soundcard (RME Babyface). It is remapped as standard audio out after the wake-up as well.

Please replace XXXX with your user name or remove the logs.


#!/bin/bash
#
# NAS Server name
server=YourNAS
#
# SMB Shares
shares="ShareA ShareB ShareC"
#
echo "Stop possible Timemachine backups…"
#
tmutil stopbackup
sleep 5
#
# Looking at local disk on USB or firewire
#
mount | grep /dev/disk | grep -v disk1 | grep -v cddafs | awk '{printf("%s\n", substr($0,index($0,"/Volumes/")+9,index($0,"(")-index($0,"/Volumes/")-10) )}' | while read USBDrive;
do
echo "Unmounting $USBDrive ..."
echo "$USBDrive" | xargs -I{} osascript -e 'tell application "Finder" to eject (disks whose name is "{}")'
done
sleep 5
echo ""
echo "Unplug the USB drives now!"
sleep 10
echo "Going to sleep now ..."
sleep 2
pmset sleepnow
echo "Wait until USB drives come back ..."
sleep 10
/usr/sbin/diskutil list | grep -e ' \+[0-9]\+: \+[^ ]\+ [^ ]\+' | grep -v "Recovery" | grep -v disk1 | sed 's/.*\(disk[0-9].*\)/\1/'| while read HWDrive;
do
echo "Mounting again $HWDrive ..."
/usr/sbin/diskutil mount "$HWDrive"
done
#
# Recovering SMB mounts as the crappy apple automountd is so buggy and will not handle user permission
#
for share in $shares
do
if [ -e "/Volumes/$share" ]
then
echo `date` "/Volumes/$share mountpoint exists" >> /Users/xxxx/Library/Logs/automount.log
else
echo `date` "/Volumes/$share mountpoint created" >> /Users/xxxx/Library/Logs/automount.log
mkdir /Volumes/$share
fi
if [ `mount | grep -c "on /Volumes/$share"` -gt "0" ]
then
echo `date` "/Volumes/$share mounted already" >> /Users/xxxxx/Library/Logs/automount.log
else
echo `date` "/Volumes/$share mounting" >> /Users/xxxxxx/Logs/automount.log
echo "Mounting again SMB $share ..."
mount -t smbfs -o soft //user:pw@$server/$share /Volumes/$share
fi
done
#
echo "Restoring Sound to Babyface…assuming in the office"
osascript <<EOF
tell application "System Preferences"
reveal anchor "output" of pane id "com.apple.preference.sound"
end tell
tell application "System Events" to tell process "System Preferences"
tell table 1 of scroll area 1 of tab group 1 of window 1
select (row 1 where value of text field 1 is "Babyface (23131609)")
end tell
end tell
quit application "System Preferences"
EOF
#
echo "Done. Have Fun!"
sleep 5





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2014 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   PHP hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy