Tuesday, September 27, 2022

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

Mr. Science
Member
From:: Satellite Beach, Florida
Registered: 2015-08-13
Posts: 76
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: 195

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: 76
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: 76
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

 

#5 2022-05-26 03:40:37 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2524

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

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:

Applescript:


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

Last edited by KniazidisR (2022-05-26 04:31:12 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#6 2022-05-26 08:59:48 am

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

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

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

Applescript:


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)

Last edited by robertfern (2022-05-26 09:11:07 am)

Offline

 

#7 2022-05-26 10:05:02 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2524

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

@robertfern,

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

Last edited by KniazidisR (2022-05-26 10:05:59 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#8 2022-05-28 06:56:17 am

Fredrik71
Member
Registered: 2019-10-23
Posts: 970

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

Other approach could be to use the plist format.
And its very easy with AppleScriptObjC

Ps. the do shell script is only there to execute the command and make tmp file.

Applescript:

use framework "Foundation"
use scripting additions

property tmpFile : POSIX path of (path to temporary items) & "plist.tmp"

set tmpPlist to do shell script "hdiutil info -plist > " & quoted form of tmpFile

set theKeyImage to my (dictFromPlist(tmpFile)'s valueForKey:"images")

tell theKeyImage
   (its valueForKey:"image-path") as string
end tell

on dictFromPlist(theFile)
   set thePath to tmpFile
   set theURL to current application's |NSURL|'s fileURLWithPath:thePath
   set theDict to current application's NSDictionary's dictionaryWithContentsOfURL:theURL |error|:(missing value)
end dictFromPlist


Node-RED makes it easy to automate IoT

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)