PDA

View Full Version : script to mount drive, and unmount if already mounted




seydurin
Nov 18, 2010, 12:07 PM
I have two harddrives in my macbook pro (one in the optibay), and I find myself unmounting one of them when I don't need it, to save power. It's a little annoying having to mount and unmount manually every time, so I was hoping I could be done with an applescript. Can it be done?

I tried this, but it returned syntax error "Expected end of line, etc. but found ":



set myVolumeLabel to "Storage HD"

tell application "GrowlHelperApp"
set the allNotificationsList to {"Disk mounted", "Disk unmounted"}

register as application "Disk Mounter" all notifications allNotificationsList default notifications allNotificationsList icon of application "Disk Utility.app"
end tell

tell application "Finder"
set diskDev to do shell script "diskutil list | grep \"" & myVolumeLabel & "\" | grep -o 'disk[1-9]*' "
if not (disk myVolumeLabel exists) then
do shell script "diskutil mountDisk " & diskDev
tell application "GrowlHelperApp" to notify with name "Disk mounted" title "Volume mounted" description "Disk " & diskDev & " with volume " & myVolumeLabel & " has been successfully mounted." application name "Disk Mounter" icon of application "Disk Utility.app"
else
do shell script "diskutil unmountDisk " & diskDev
tell application "GrowlHelperApp" to notify with name "Disk unmounted" title "Disk unmounted" description "Disk " & diskDev & " with volume " & myVolumeLabel & " has been successfully unmounted." application name "Disk Mounter" icon of application "Disk Utility.app"
end if
end tell