This Automator folder action will monitor the Downloads folder for new dmg files and automatically unpack them into a similarly named sub directory. It requires no interaction from the user. On completion a notification will display.
As mounting and extraction happens in the background you save time, since you can continue to work. In addition with all disk image contents pre-copied to disk, moving any .app to "/Applications" is pretty much instant (or in the case of Vivaldi, you could run it in standalone mode directly from the created extraction folder).
- Open the
Automator.app
(part of macOS) and create a new "Folder Action" - Choose the Downloads folder
- Drag "Run Shell Script" (found under "Utilities") into the actions area
- Change the Pass Input drop down to "as arguments"
- Replace the example code with the following:
for DMG in "$@"; do
# To unpack only Vivaldi dmgs, uncomment the next line and then comment out the one after it
# if echo "$DMG" | grep -qE '/Vivaldi\.([0-9]+\.){3}[0-9]+.*\.dmg$'; then
if [ ${DMG: -4} == ".dmg" ]; then
DIR="${DMG%.dmg}"
if [ ! -e "$DIR" ]; then
mkdir -p "$DIR/.mnt"
yes Y | hdiutil attach "$DMG" -mountpoint "$DIR/.mnt" -nobrowse
cp -R "$DIR/.mnt/" "$DIR"
hdiutil detach "$DIR/.mnt"
rmdir "$DIR/.mnt"
osascript -e "display notification \"${DMG##*/}\" with title \"Extraction complete\" sound name \"Pop\""
elif [ -d "$DIR/.mnt" ]; then
# This is just to clean things up if something went wrong before
hdiutil detach "$DIR/.mnt"
rmdir "$DIR/.mnt"
fi
fi
done
- Save the action with an appropriate name (e.g. "auto-unpack-dmgs")
- Download a dmg file and wait
This Automator folder action will auto-agree to any license. I am not a lawyer but I doubt that means the license does not apply. 😉