With a little side of applesauce...

Monday, January 31, 2011

OS X / hdiutil - acquire mount point on command line

When I was trying to automate the installation of XiphQT, I was struggling to find the mount point after Finder opened the dmg. I found that I could tail -n1 the output of the hdiutil attach my.dmg and use that output:

# move to the location of our dmg file
cd ~/Downloads

# We need to change the separator for the for loop,
# (in case mountpoint has whitespace)

# mount the dmg, and output the final line of output which looks like:
# /dev/disk2s1 Apple_HFS /Volumes/XiphQT 0.1.9
for m in $(hdiutil attach xiph-qt-0.1.9.dmg | tail -n1 ) ; do

# set our mount point for future use
# (change our FIELD SEPARATOR to tab, in case of whitespace in mountpoint)
mp=$(echo $m | awk 'BEGIN {FS="\t"}; {print $3}')

# set our destination folder

# create our destination folder
cd ; mkdir "${dest}"

# copy our component into the destination folder
cp -R ${mp}/XiphQT.component "${dest}"

# detach our mountpoint
hdiutil detach ${mp};

No comments: