This macOS workflow (Create Encrypted Image.workflow
) is an Automator Quick Action, which adds a context popup on folders in Finder. When activated, the workflow launches a new Terminal window that helps users encrypt a folder and its contents. The resulting DMG disk image requires a password to unlock.
The workflow installs under ~/Library/Services
. Just delete Create Encrypted Image.workflow
from there and it's all gone!
You can use Touch ID to authorize sudo
, which I find pairs nicely with this workflow. See how here:
https://gist.github.com/fraune/0831edc01fa89f46ce43b8bbc3761ac7
on run {input, parameters}
set folderPath to POSIX path of item 1 of input
tell application "Terminal"
activate
do script "sudo hdiutil create -size 20mb -fs apfs -encryption AES-256 " & quoted form of folderPath & " -srcfolder " & quoted form of folderPath & "; exit"
end tell
return input
end run
Set the folderPath variable to be the input folder
set folderPath to POSIX path of item 1 of input
Open Terminal.app, and bring it to the foreground
tell application "Terminal"
activate
...
end tell
Do the encryption work
do script "sudo hdiutil create -size 20mb -fs apfs -encryption AES-256 '" & folderPath & "' -srcfolder '" & folderPath & "'; exit"
Notes:
- This is some AppleScript that runs a Bash command, expanding the
folderPath
variable into the hdiutil arguments - My understanding is that
-size 20mb
just sets the initial size. The resulting DMG will be more or less, depending on what you encrypt. -fs apfs -encryption AES-256
sets the filesystem type and encryption type to use. Last I checked, AES-256 is the best encryption supported byhdiutil
in this context.- The
folderPath
variable is used twice: as the input path, and as the output path. The output path will automatically append.dmg
onto the end offolderPath
when the command completes.
- Add notification upon successful completion (inspiration)