Monday, May 4, 2026

Creating encrypted disk photographs with `hdiutil` from a script

I’ve a script that makes use of hdiutil to create a disk picture from a folder, and encrypt that disk picture, and reserve it to a particular location.

Previously, this was straightforward to do. You set a flag in your encryption time, and a flag in your password, and it was all good. However now the password flag is deprecated and throws an error that kills the dad or mum script.

Now you must use -stdinpass to immediate for the password on the terminal. Thats nice of I am scripting this command by hand however its in a script, so what can I do? Is there a way of setting the password that does not require direct person interplay? Or is it simply damaged completely now?

I made the error of asking chatgpt this query. It informed me to go the password like so:
echo "password" | hdiutil ...

So that is the total command that my script finally ends up making an attempt to run:
echo "password" | hdiutil create -srcfolder '/Volumes/Disk/Folder to be imaged/' -format ULMO -encryption AES-256 -stdinpass '/Customers/me/Desktop/Folder to be imaged.dmg'

That does create a password protected, encrypted disk picture. However the password I give it doesn’t open it.

On the suggestion of @aMike I used echo -n "password" | hdiutil . . . as an alternative. Attention-grabbing outcome….

If I copy that complete command into the terminal, it really works accurately. If that precise command is run by my AppleScript, I get a .dmg that will not unlock with “password”. Very curious.

It needs to be similar. I am actually outputting the command in a dialog, after which with out altering it in any respect, working it through do shell script

That is the applescript line that runs assembles and runs the cunal command:
RunCommand("echo -n "" & MyPassword & "" | hdiutil create -srcfolder " & (quoted type of POSIX path of MyFolder) & MyFormat & " -encryption AES-256 -stdinpass " & merchandise 1 of MyNewDMG, merchandise 2 of MyNewDMG)

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles