17

I'm automating my Mac installation using puppet. As a part of it I need to install several programs that come in a .dmg format.

I use the following to mount them:

sudo /usr/bin/hdiutil mount -plist -nobrowse -readonly -quiet -mountrandom /tmp Program.dmg

The problem is that some .dmg files come with a license attached, and so script is stuck accepting the license. (There is no stdin/out when running with puppet, so I can't manually approve it to continue.)

Is there a way to pre-approve or force-approve the license?

2
  • Could possibly go on SF; you're dealing with issues that arise from working with many machines. However, it could also go here.
    – Kevin M
    Dec 25, 2010 at 21:10
  • 2
    Do "yes | hdiutil attach disk.dmg > /dev/null" - that'll type a 'Y' for you.
    – mauvedeity
    Oct 8, 2011 at 11:35

7 Answers 7

2

If you have a GUI and are able to perform two command-line calls in parallel, you can use

/System/Library/CoreServices/DiskImageMounter.app/Contents/MacOS/DiskImageMounter /path/to/file.dmg

and

osascript accept.scpt

the latter of which executes the following AppleScript:

tell application "System Events"
    delay 5 # wait 5 seconds -- I tested it using two terminal tabs and needed the time
    key code 48 # press tab 4 times in the license window
    key code 48
    key code 48
    key code 48
    keystroke " " # press space to click "accept"
end tell

In bash, I'm able to write

/System/Library/CoreServices/DiskImageMounter.app/Contents/MacOS/DiskImageMounter file.dmg & osascript accept.scpt
3
  • I forgot to mention that I don't use puppet. This answer might therefore be terribly useless, but since it's been a few days, I posted anyway.
    – Daniel Beck
    Dec 25, 2010 at 21:14
  • hmm I get an error when trying to run osascript accept.scpt ➜ dotfiles git:(master) ✗ osascript accept.scpt osascript: accept.scpt: No such file or directory
    – grant
    May 26, 2015 at 19:13
  • @grant You have to create the file with the specified content first.
    – Daniel Beck
    May 26, 2015 at 19:33
20

This worked for me when I encountered a .dmg that contained a EULA which I wanted to install it via the command line with no user interaction...

/usr/bin/hdiutil convert -quiet foo.dmg -format UDTO -o bar
/usr/bin/hdiutil attach -quiet -nobrowse -noverify -noautoopen -mountpoint right_here bar.cdr

(note: I am reasonably sure not all of the above options are needed to bypass the EULA, such as -nobrowse, -noverify, -noautoopen, -mountpoint. However, I used them and I didn't test without them so I didn't want to claim something that I hadn't tested.)

What I ended up with was a directory with

bar.cdr
foo.dmg
right_here/

where right_here/ contained the contents of the foo.dmg without being prompted for the EULA.

Be sure to detach when you are done!

/usr/bin/hdiutil detach right_here/

For more information: hdiutil(1) Mac OS X Manual Page.

YMMV

2
  • 1
    Thanks -- this worked well with a multi-page agreement, where a repeated 'y' didn't work. Sep 17, 2012 at 22:14
  • 1
    Worked for me too. Although I just needed the first line to convert it to a cdr file, then I can just attach it without all those argument and it works.
    – Maxime
    Nov 20, 2017 at 21:17
7
+50

If it just needs "Y" typed in, then pipe the yes command into the hdiutil command:

yes | /bin/hdiutil [...]

That will emulate pressing 'y' and return at the command line.

To type something else, just put it on the command line as a parameter:

yes accept | ...

That'll enter 'accept' into the script.

Note that if the script asks for input multiple times, the yes command will put multiple entries in. You may see output like 'broken pipe' - this just means that the command you piped into quit while 'yes' was still sending input.

1
  • I've never tried this, so I didn't know about the stout redirect. Thanks for the +50!
    – mauvedeity
    Oct 10, 2011 at 22:26
6

I recently came across a DMG that had a EULA and it was really irritating me since I couldn't script around it. I figured out if I converted the DMG to a CDR it bypassed the EULA on mounting the CDR.

Here's what I did:

hdiutil convert foo.dmg -format UDTO -o bar.cdr
hdiutil attach bar.cdr
rm foo.dmg <--optional

Hope this helps.

1
  • This helped me a ton! The yes | hdiutil... solutions would hang for me when called from a python script for some crazy reason. Apr 16, 2015 at 3:37
1

If you have a multi-paged EULA that you need to accept, you can get to the accept part by putting a q before the rest of your accept command (since all you need is an accepted quit command in less, you could also use ZZ or Q).

For example, if the EULA requires you to type a y to accept you'd run:

yes qy | hdiutil attach ...
1
  • This works, but it leaves the process silently hanging afterwards.
    – BSUK
    Mar 26, 2020 at 1:35
1

The "yes" solution above didn't work on Big Sur, and I realized this is because the EULA is piped through the pager, which can be changed with the environment variable PAGER for me. The following command works instantly and automatically with the expected output:

$ yes | PAGER=cat hdiutil attach <imagename>
<EULA>
expected   CRC32 $228777A9
/dev/disk2              GUID_partition_scheme
/dev/disk2s1            Apple_HFS                       <mountpoint>
0

Shouldn't you be using puppet's own tools to install packages? I'm a radmind admin myself and I'm not familiar with puppet, but a check on their wiki reveals that there is a tool called pkgdmg that might do the equivalent of what you're trying to accomplish.

http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Mac_Osx#packagepkgdmg

2
  • 1
    it doesn't handle apps that require accepting license. Feb 3, 2011 at 19:39
  • Indeed; I was under the impression that you would be creating your own packages with no need for a license acceptance. Such is the mindset of a Radmind admin, I suppose.
    – NReilingh
    Feb 3, 2011 at 22:51

You must log in to answer this question.

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