The Computer Oracle

Bypass a licence agreement when mounting a DMG on the command line

--------------------------------------------------
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------

Music by Eric Matyas
https://www.soundimage.org
Track title: Popsicle Puzzles

--

Chapters
00:00 Bypass A Licence Agreement When Mounting A Dmg On The Command Line
00:33 Accepted Answer Score 2
01:05 Answer 2 Score 20
01:59 Answer 3 Score 7
02:35 Answer 4 Score 6
02:54 Thank you

--

Full question
https://superuser.com/questions/221136/b...

--

Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...

--

Tags
#macos #dmgimage #hdiutil

#avk47



ANSWER 1

Score 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




ANSWER 2

Score 7


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.




ANSWER 3

Score 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.




ACCEPTED ANSWER

Score 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