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
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.
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.
-- 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