Even with the growth of the Mac App Store, I still find myself constantly downloading, mounting and eventually deleting DMGs. Almost just as frequently, I am greeted with the following dialog whenever I try to empty the Trash with a mounted disc image file inside it:
Fortunately for us, we can overcome this annoyance by creating a Folder Action in Automator. Folder Actions run whenever the contents of a specified directory change – in this case, that will be the current user's Trash. Our Folder Action will eject any mounted disc image files moved to the Trash.
- Open Automator, which can be found inside the
- Create a new document and select 'Folder Action' from the template chooser.
- Click on the 'Choose folder' pop-up button and select 'Other…" from the menu that appears.
- When the 'open' panel comes up, hit Shift+⌘+G and enter
~/.Trashin the location field; click 'Go', followed by 'Choose'.
- Drag a new instance of the 'Run Shell Script' action (listed under the Utilities group) from the Library into your workflow.
- Set the action's shell to
/usr/bin/pythonand its input type to 'as arguments'.
- Finally, replace the contents of the placeholder script with the one listed below.
Once your new Folder Action is saved, any mounted disc image files dragged to the Trash will be ejected automatically.