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


Click here to return to the 'Update to unmount internal drives' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Update to unmount internal drives
Authored by: nickv2002 on Feb 13, '12 02:56:49PM
I wanted to use this script to mount and unmount an internal disk partition. Unfortunately, the Apple Script-able Finder does not consider internal partitions ejectable the script would only mount the disk but not unmount it. So I copied the logic from the mounting aspect of the script to have diskutil unmount the disk via a command line call which did the trick. Here's the updated version:

set diskName to "diskname"

tell current application
	set deviceLine to (do shell script "diskutil list | grep \"" & diskName & "\" | awk '{ print substr($0,69,9) }'")
	if deviceLine = "" then
		display dialog "The disk \"" & diskName & "\" cannot be found." buttons {"OK"} default button 1 with title "Error" with icon caution
	end if
	set foundDisks to paragraphs of deviceLine
end tell

tell application "Finder"
	if disk diskName exists then
		tell current application
			repeat with i from 1 to number of items in foundDisks
				set this_item to item i of foundDisks
				if this_item contains "disk" then
					do shell script "diskutil unmount /dev/" & this_item
				end if
			end repeat
		end tell
	else
		tell current application
			repeat with i from 1 to number of items in foundDisks
				set this_item to item i of foundDisks
				if this_item contains "disk" then
					do shell script "diskutil mountDisk /dev/" & this_item
				end if
			end repeat
		end tell
	end if
end tell
Edited on Feb 13, '12 03:18:15PM by nickv2002


[ Reply to This | # ]
Update to unmount internal drives
Authored by: jedics on Apr 11, '12 08:57:44AM

this worked for me but it doesnt seem to spin the drive down like it does when I eject manually from the finder.

anyone else have this problem?



[ Reply to This | # ]