Tuesday, November 19, 2019

#1 2019-11-09 12:49:14 pm

Mr. Science
Member
From:: Satellite Beach, Florida
Registered: 2015-08-13
Posts: 46
Website

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


"Fail and fail until you fail to fail!"   ~   http://www.theMrScienceShow.com

Offline

 

#2 2019-11-09 03:06:15 pm

robertfern
Member
Registered: 2011-11-29
Posts: 44

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

Hows about using the command line "hdiutil info"

Applescript:

do shell script "hdiutil info"

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

Last edited by robertfern (2019-11-09 03:07:08 pm)

Offline

 

#3 2019-11-09 04:10:30 pm

Mr. Science
Member
From:: Satellite Beach, Florida
Registered: 2015-08-13
Posts: 46
Website

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

Fantastic! Thanks, robertfern!!

Here's what I used ...

Applescript:


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!)

Applescript:


return do shell script "hdiutil imageinfo " & posixPATHtoSomeDMG

Cheers!:D


"Fail and fail until you fail to fail!"   ~   http://www.theMrScienceShow.com

Offline

 

#4 2019-11-09 05:30:33 pm

Mr. Science
Member
From:: Satellite Beach, Florida
Registered: 2015-08-13
Posts: 46
Website

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

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 

Applescript:


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


"Fail and fail until you fail to fail!"   ~   http://www.theMrScienceShow.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)