Identify connected external disks programmatically

Have you considered using diskutil info /dev/disk[n|s{n}] | grep Ejectable which allows you to identify whether the device (or device slice) is ejectable.

This would need to be expanded upon in a script using awk to work through each disk device that is currently attached to determine whether it can be ejected and then eject it.


In a terminal window (bash shell)

diskutil info /Volumes/name-of-volume

will return a list of properties of the volume, including

Protocol: FireWire ... Ejectable: Yes Whole: No Internal: No

so, I suppose you could start with that. I'm not clear on what the "Internal" property implies, it might be better to look at "Protocol" if your concern is with Firewire or USB external devices.