Distinguish mounted disk images from other volumes

I’d like to distinguish between volumes mounted from disk images and all other disks. I can’t find an obvious way to do this, like to ask for the volume’s device. I looked in System Profiler but aside from having to parse the produced text, it doesn’t seem like it will give me enough information to work in all situations (like with network volumes). Does anyone here know of a way to accomplish this task from AppleScript, or is it impossible?

Hi,

Maybe you can look at the properties of the disks and find a difference. I don’t have access to network volumes.

set disk_list to (list disks)
set info_list to {}
repeat with i in the_disks
tell application “Finder”
try
set end of info_list to (properties of disk i)
end try
end tell
end repeat
return info_list

gl,

I hadn’t tried that. Good idea, but unfortunately it turned up nothing. As far as the Finder and standard scripting additions are concerned, a volume is a volume is a volume.

Um, no, that’s not really true: volumes can be local or not, removable or not, etc. While it doesn’t exactly answer your original question, it does narrow down the list of disks if you use some of the properties available to either the Finder or System Events:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

I had a feeling ‘local volume’ would do it. Wonder why Gordon didn’t get that?

Thanks Jon,

I had hoped that would be it at first, too, but I have firewire drives (four of them actually) and a USB drive mounted, all of which say they are local disks. So yes, I can narrow down which ones might be disk images, but can’t get there completely (short of hardwiring in the names of the localdisks that are ejectable, but then that defeats the purpose of the script).

Can’t remember if I said this or not, but my script’s goal is to eject all externally connected volumes. This would include everything over firewire, USB, and network. What I don’t want to eject are disk images. Writing a script that ejects all ejectable volumes was trivial, but identifying the disk images is proving tougher.

The diskutil CLI tool should be able to tell you if a disk is mounted from an image. That information coupled with the names of all the mounted disks should be enough for what you want to do (assuming that there is nothing open on the local or networked disks to eject):

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Perfect. I’m currently running wireless so I can’t test it fully, but my script seems to be working. Here it is:

set volumesToEject to {}

tell application "Finder"
	--get the disks in a list
	set volumes to every disk
	if volumes is startup disk then
		set volumes to {volumes}
	end if
	
	--test if we want to eject
	repeat with volume in volumes
		set POSIXpath to quoted form of ("/Volumes/" & volume's name)
		try
			if (do shell script "diskutil info " & POSIXpath) does not contain "Disk Image" then set end of volumesToEject to volume
		end try
	end repeat
	
	--eject if ejectable
	repeat with volume in volumesToEject
		try
			eject volume
		end try
	end repeat
end tell

Many thanks guys!

This could be condensed down to:

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]