Any way to read Get Info's "Disk Image" property without a window?

I’m working on an applescript to manage the opening and closing of .dmg files.
When a disk image is attached and mounted(in Sierra), it’s “Get Info” window provides a property named “Disk Image” which is a handy path back to it’s original file.
Since many of the files I’m seeking to manage are similarly named and the expanded images are differently named, it would be very helpful to access that string from the “Get Info” window but without opening numerous additional windows for each file being handled.
• I’ve tried peeking at metadata using a do shell & mdls but didn’t see it there.
• I did find a script that reads the “Get Info” window, but it must first be opened.
• I noticed different info windows are available via (command+i) and (command+shift+i), but I don’t know if that was a clue or not.

Is there a shortcut to accessing the original file path of an opened disk image?

Thanks in advance for any ideas.

Model: Mac Pro
AppleScript: 2.9
Browser: Safari 602.1.50
Operating System: macOS 10.14

Hows about using the command line “hdiutil info”

do shell script "hdiutil info"

you can parse out the result for the line starting with ‘image-path’

Fantastic! Thanks, robertfern!!

Here’s what I used …


set openImgINFO to (do shell script "hdiutil info ")
set dmgFILE to text ((offset of ": " in (paragraph 4 of openImgINFO)) + 2) thru -1 of (paragraph 4 of openImgINFO)
set dskIMAG to text ((offset of "	/" in (paragraph -1 of openImgINFO)) + 1) thru -1 of (paragraph -1 of openImgINFO)
return {dmgFILE, dskIMAG}

It was interesting to also find that this returned an error if the .dmg file was open.(very useful!)


return do shell script "hdiutil imageinfo " & posixPATHtoSomeDMG

Cheers!:smiley:

Heres a nicer script for anyone following this that needs it.
It loops thru each open disk image then reports …

  • its original file path,
  • its open disk path
  • its disk id

set openImgINFO to (do shell script "hdiutil info ")
set rprt to return
set {dmgFILE, dskIMAG} to {"", ""}
if ((count of (paragraphs of openImgINFO)) < 4) then return "No open disk images detected."
repeat with eachLINE in paragraphs of openImgINFO
	if (text 1 thru 10 of eachLINE is "image-path") then set dmgFILE to text ((offset of ": " in eachLINE) + 2) thru -1 of eachLINE
	if (text 1 thru 5 of eachLINE is "/dev/") and (eachLINE contains "	/") then
		set dskID to word 2 of eachLINE
		set dskIMAG to text ((offset of "	/" in eachLINE) + 2) thru -1 of eachLINE
		set rprt to rprt & dmgFILE & ", 	" & dskIMAG & ", 	" & dskID & return & return
		set {dmgFILE, dskIMAG} to {"", ""}
	end if
end repeat
return rprt

As I see, the hdiutil utility doesn’t report my mounted flash drive. Although, in the computer-object window, it is shown connected in the same way as Network, HD disk, DMG disk images.

My question is: how do I get information about all connected disk images? Including Hard disk, DMGs, Network disk and mounted flash drives?

Update:

I found the answer myself. Following will get info for all disks, including Hard disk, mounted DMGs, Servers and Flash Drives:


tell application "Finder"
	set infoList to properties of disks of folder "Volumes" of startup disk
	set end of infoList to properties of startup disk
end tell

infoList

Your script doesn’t work for me

the line – set infoList to properties of disks of folder “Volumes” of startup disk –
should be just – set infoList to properties of disk


tell application "Finder"
	set infoList to properties of disks
	set end of infoList to properties of startup disk
end tell

infoList

Just so you know “hdiutil” only lists disks mounted from .dmg (ie disk images)

@robertfern,

I agree that your version is better. I will use it in the future. Thanks.