mounting disk image with password

I made a password protected disc image on an external hard disk that I would like to mount via applescript.

To mount it I use:

do shell script "hdiutil attach  /Volumes/ExternalDisk/ImageName.dmg"

This mounts the disk image fine at which point the password dialog box opens up. I figured I could enter the password using the “keystroke” command or trying something like:

tell application "System Events"
tell application process "SecurityAgent"
tell window 1
set value of text field 1 to "Password"
end tell
end tell
end tell

The problem is the script stops at the ‘do shell script’ with the password dialog box open waiting for the password, and thus you can’t enter the password after that using the script. The question is then, how can you open the disk image with the required password imbedded in the do shell script and thus bypass the password dialog box? Normally I add:
"user name " & admin_name & " password " & admin_password
after the script, but that’s not the password the dialog box is looking for. It’s looking for the password for the disk image. Hmmm.

Any help would be greatly appreciated.:rolleyes:

Hi,

have you tried the direct method


property thePassword : "¢¢¢"
do shell script ("/bin/echo -n " & quoted form of thePassword & " | /usr/bin/hdiutil attach -stdinpass  /Volumes/ExternalDisk/ImageName.dmg")

StefanK, that was brilliant. It works like a charm. I truly appreciate your help. Again, thank you very much.:lol: