Mount a DMG but not show on the desktop

rbingham917
New Contributor III

Hello everyone- I have a very ultra noobish question. I'm using hdiutil in a script to mount installation DMG's on a system for imaging, but when I call it within my script, it shows the DMG contents on the desktop. I would like to know how to go about suppressing that, I'd like to have one less thing for them to mess with.

command that I am using is hdiutil attach /path/to/dmg

then I run it, and

hdiutil detach /path/to/dmg

5 REPLIES 5

thoule
Valued Contributor II

So close...

hdiutil attach /path/to/dmg -nobrowse

rbingham917
New Contributor III

@thoule

Thank you so much. Greatly appreciated. The growing pains of a novice scripter:)

thoule
Valued Contributor II

@rbingham917 I admit I didn't know the answer to this question, but I knew it was possible. So 'man hdiutil' and read the man(ual) page and notice the following line.

-nobrowse render any volumes invisible in applications such as the OS X Finder.

The real power in scripting is not remembering command and parameters, but knowing where to find them. Good luck with your coding.

geoffrepoli
Contributor

Maybe I can pick some brains here... am I doing way too much work with how I've always done silent mounting? My typical script would look something like this:

#!/bin/bash

url="http://www.server.com/path/to/file.dmg"
dmgPath="/tmp/file.dmg"
/usr/bin/curl -s --output "$dmgPath" "$url"
mountPoint=$(/usr/bin/mktemp -d /tmp/file.XXXX)
/usr/bin/hdiutil attach "$dmgPath" -mountpoint "$mountPoint" -noverify -nobrowse -noautoopen
# /usr/sbin/installer or whatever else you are doing with the contents in the dmg
/usr/bin/hdiutil detach "$mountPoint"
/bin/rm -rf "$mountPoint"
/bin/rm -rf "$dmgPath"

exit 0

Do I really only need to add the -nobrowse option and avoid all the mktemp work?

bentoms
Release Candidate Programs Tester

@grepoli Not really.

The mktemp does make sure that the DMG mounts at a random path.

Tbh, I'd stay with what your doing. :)