2 Replies Latest reply: Oct 3, 2006 3:24 PM by Khadrelt
Khadrelt Level 1 Level 1 (5 points)
I'm trying to find a way to make an AppleScript that will mount an encrypted disk image and enter the password for it automatically. I can make it open all right, but I can't figure out how to make it enter the password (the 'with password' command doesn't seem to work, I'm assuming it only works on remote volumes?).

Any help would be appreciated.

1.25 gHz Mini, Mac OS X (10.4.6)
  • Steve Herman1 Level 4 Level 4 (2,545 points)
    Something like this should work:
    <pre>
    set myResult to display dialog "Enter password:" default answer "" with hidden answer
    set thePW to text returned of myResult

    set cmd to "echo -n \"" & thePW & "\" | hdiutil attach /path/to/encrypted/disk/image.dmg -stdinpass"
    do shell script cmd
    </pre>
    There are some security concerns with passing a command string to "do shell script" that contains your password. If other users log on to your machine they could see your password if they happened to be watching the process list at just the right time.

    Steve
  • Khadrelt Level 1 Level 1 (5 points)
    That worked perfectly! Thanks a lot.