Ejecting a partitioned external drive

It was once the case that you could eject the partitions of a disk thus:

tell application "Finder"
	set DiskNames to {"G5-BKUP", "iMac-BKUP", "iMac-Spare"}
	set allDisks to name of disks
	repeat with aDisk in allDisks
		if aDisk is in DiskNames then eject aDisk
	end repeat
end tell

In Snow Leopard and Lion, however, a dialog appears when you eject one partition of a disk asking if you want to eject the other two. How do I avoid that in a script and just eject the entire external drive?

Don’t know if this will help at all but worth a shot:

tell application "Finder"
	set allVolumes to the name of every disk
	repeat with i from 1 to the count of allVolumes
		if item i of allVolumes is not the name of the startup disk then
			-- Uncomment the 2 lines below if you don't want Network drives unmounted.
			-- if item i of allVolumes is not "Network" then
			eject (item i of allVolumes)
			-- end if
		end if
	end repeat
end tell

from http://www.bitcontrol.org/2008/02/06/applescript-to-unmount-all-drives/

Unfortunately, when the first partition is ejected, I still get the dialog asking if I want to eject just that partition or all of them. I’m guessing I’ll have to respond to the dialog since I haven’t figured out a way to avoid it.

Hi, Adam.

I can’t try it with my Snow Leopard machine, but “diskutil” looks hopeful. Something like:

do shell script "diskutil unmount '/Volumes/Partition name'"

I have just discovered (in Lion, at least) that the shell command diskutil eject disk2 will do it – it ejects the partitions one at a time and then the disk itself. Since I have more than one external disk, I’ll identify it’s partitions first by parsing diskutil list names to make sure that #2 is the one I want. I’ll post whatever I come up with.

This phrase seems to work nicely:

-- grab the whole readout for that disk with 3 partitions
set D to do shell script "diskutil list | grep -C 5 'iMac-BKUP'"
-- get the number of the disk the partition is on
set N to last character of first paragraph of D -- the disk number
-- eject the whole disk and its partitions.
do shell script "diskutil eject disk" & N

Thanks, All, and Happy New Year!