Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Steps to attach a dmg disk image using hdiutil while capturing the mount point and dev entry for detaching when done
# use process redirection to capture the mount point and dev entry
IFS=$'\n' read -rd '\n' mount_point dev_entry < <(
# mount the diskimage (leave out -readonly if making changes to the file system)
hdiutil attach -readonly -plist "$dmg_path" | \
# convert output plist to json
plutil -convert json - -o - | \
# extract mount point and dev entry
jq --raw-output '
.[] | .[] |
select(."volume-kind" == "hfs") |
."mount-point" + "\n" + ."dev-entry"
# work with the file system
echo "ls $mount_point:"
ls "$mount_point"
# unmount the disk image (use the -force option if necessary)
hdiutil detach "$dev_entry"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.