How to Delete DMG Files Automatically on Mac – Guide

Macs require a more involved process for installing applications than Windows PCs, involving mounting and unmounting disk images. This can be time-consuming, making it difficult to quickly test multiple apps.

Using Automator, Mac users can now quickly and easily eject and delete disc images after installing applications with just a few clicks.

Creating Automator workflows is a great way to streamline tasks.

Automatically delete DMG files when you eject them

Open Automator and create a Service document, a type of document available in the dialog box.

Choose ’no entry’ and ‘Finder’ from the drop-down menus in the right panel to get the desired result.

In Automator, locate the ‘Run AppleScript’ action and drag it to the right panel. This will open an AppleScript window with some default code.

Replace the existing code with this new one: Copy and paste the following into the script box.

The Finder application should be used to select a mounted volume from a disk image. If the selection is not a volume, an error message will appear. If the selected volume is a disk image, it will be moved to the trash and revealed in its original location.

Save the Automator service with a memorable name.

With one click, you can unmount and delete disk image files after they’ve been mounted. All you need to do is select the file in Finder, then select Services and Eject and Delete (or whatever name you have given the service).

This Automator workflow takes a different approach to the same task, working in reverse.

Eject DMG files automatically by dragging them to the trash

This Automator workflow lets you avoid the message that appears when you drag a mounted DMG file to the trash.

Follow these steps to make it happen:

Automator users can create a Folder Action by selecting the Folder Action document type when creating a new document.

To access the Trash folder, select ‘Other…’ from the drop-down menu in the right panel, then type ‘~ / .Trash’ in the dialog box that appears.

Drag the “Run Shell Script” action to the right pane, then select “/usr/bin/python” in the two drop-down menus that appear.

Replace the placeholder script in the script box with the following: Copy and paste this new script into the box to complete Step 4.

If an image path specified in the command line arguments is found in the output of “hdiutil info”, this code will eject the corresponding device.

With just a few clicks in Automator, you can set up your Mac to automatically unmount DMG files when they’re dragged to the Trash.

Create keyboard shortcuts for your most-used actions with this tutorial.

With two options available, Mac users can now easily enable a process feature. Whether you choose to use Automator or the Terminal, you’ll gain a better understanding of how the program works. So pick your preferred method and get started!

Final note

Share this guide to help your Mac friends delete DMG files automatically. Got questions? Ask us!