I tried hdiutil info -plist, but if I shift the DMG file elsewhere after mounting it, it doesn't update the DMG path. If I right click and select 'Get info' on the volume, I'm able to view the correct DMG path.

  • Hello Shruti, welcome to Ask Different. I've tried to reproduce your issue: I've mounted a DMG file by double-clicking it and moved the DMG file elsewhere. I have then selected the mounted volume on the Desktop, right-clicked it and selected "Get Info" and I've noticed that the Finder stops keeping track of the disk image location (the Disk Image field in "Get Info" of the mounted volume isn't displayed). You write you are able to view the correct DMG path, could you try again and confirm that that is the case? Which is your macOS version? (I run macOS 10.13.6 "High Sierra".) – jaume Aug 31 '18 at 8:36
  • Hi jaume. I tried this on MacOS 10.12.6 desktop. Did you try it on a laptop? Not sure if that's the reason or the DMG itself. But yes, if I'm shifting it, the path in Get info changes. – Shruti Gupta Aug 31 '18 at 9:23

A somewhat pedestrian way would be to retrieve the name of your DMG file from the output of hdiutil and then search for it, e.g., via

hdiutil info -plist | grep dmg | sed 's/<string>\([^<]*\)<\/string>/\1/' | xargs basename | xargs mdfind -name

You may need to modify the grep dmg part to be smarter if you have several images mounted, or you loop through all DMG files reported by hdiutil, e.g.,

for F in `hdiutil info -plist | grep dmg | sed 's/<string>\([^<]*\)<\/string>/\1/'`
  do basename $F | xargs mdfind -name

However, none of the above takes your mount path as input. To do that, you could add a sed command in the pipe that extracts the paragraph of interest, e.g.,

hdiutil info -plist | tail -r | sed -n '/\/Volumes\/MOUNTNAME/,/dmg/p' | grep dmg | sed 's/<string>\([^<]*\)<\/string>/\1/' | xargs basename | xargs mdfind -name

Perhaps it is also easier to work on the direct output of hdiutil info, without the -plist flag.

| improve this answer | |
  • Hi! Thanks for your suggestion. However if I have multiple DMGs of the SAME name, this would cause a problem right? I can modify grep to retrieve the DMG path where I originally mounted from, then I guess I can apply a check whether this DMG still exists in that path else look for it on the computer. But yeah problem being of the same name ones on different locations. – Shruti Gupta Aug 31 '18 at 9:22
  • 1
    Try hdiutil info -plist | tail -r | sed -n '/\/Volumes\/MOUNTNAME/,/dmg/p' | grep dmg | sed 's/<string>\([^<]*\)<\/string>/\1/' | xargs basename | xargs mdfind -name, where you of course have to adapt MOUNTNAME... – monomeric Aug 31 '18 at 9:30
  • Yes but same problem will arise :P If I've multiple DMGs on computer with same name, they will all be listed. I want the specific one related to Mount path. – Shruti Gupta Aug 31 '18 at 9:57
  • Well, the sed that extracts the paragraph of your mount path takes care of that, unless all your mount points had the same path as well... that'd pose an interesting conundrum. – monomeric Aug 31 '18 at 10:14
  • 1
    There are ways to trace file system changes, cf. stackoverflow.com/questions/4429270/macos-x-file-system-watcher, however, you would probably need to know the location of your initial DMG before moving it in any case. – monomeric Aug 31 '18 at 10:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .