Thinking of that, this time we’ll share a couple of neat little workflows that you can implement on your Mac using Automator. With any of them, every time you are done with an app installation on your Mac, you’ll be able to eject/unmount and delete the disk image in just a couple of clicks. Let’s get started with how to set up these nice Automator workflows.

Delete DMG Files Automatically When You Eject Them

Step 1: Open Automator and choose to create a new document. From the available document types that show up on the dialog box, select Service. Step 2: At the top of the right panel, make sure to choose from the dropdown menus the options ‘no input’ and ‘Finder’ respectively so that the end result is as the one pictured below. Step 3: Next, on the left panel of Automator, search for the Run AppleScript action and drag it to the right panel. An AppleScript window will show up with some placeholder code in it. Delete that code and instead copy and paste the following one in the script box: tell application “Finder"set selection_list to selectionif (count selection_list) display dialog ¬"Please select a volume mounted from a disk image.” with title ¬"No Selection Found" with icon stop ¬buttons [“OK”] default button 1returnend ifset my_selection to item 1 of selection_listset my_kind to kind of my_selectionset my_name to name of my_selectionif my_kind is not “Volume” thendisplay dialog ¬"Please select a volume mounted from a disk image file." with title ¬"Selection is not a Disk Image" with icon stop ¬buttons [“OK”] default button 1returnend ifset volume_list to paragraphs of (do shell script “hdiutil info | grep ^/dev/disk | grep -o ‘/Volumes/.’")set source_list to paragraphs of (do shell script “hdiutil info | grep ^image’-‘alias | grep -o ‘/.’")set match_found to falserepeat with v from 1 to (count volume_list)if “/Volumes/” & my_name = item v of volume_list thenset match_found to trueexit repeatend ifend repeatif match_found is not equal to true thendisplay dialog ¬"The selected volume does not appear to be a Disk Image.” with title ¬"Could not find Disk Image” with icon stop ¬buttons [“OK”] default button 1returnelseset my_source to POSIX file (item v of source_list) as aliasmove my_source to the trasheject my_selection–reveal my_sourceend ifend tell Step 4: Now save this Automator service and give it a name that is easy to remember. Step 5: Once this is done, every time you have a disk image mounted, all you have to do is select it and on the Finder menu select Services and then Eject and Delete (or whatever you named the service you just created) and the disk image file will be both unmounted and deleted with one click. Now, let’s take a look at another Automator workflow that achieves the same objective doing exactly the opposite.

Eject DMG Files Automatically When You Drag Them To the Trash

As you can see from the title, this Automator workflow allows you to achieve the same purpose, except that in reverse, so you can avoid this message every time you drag to the trash a mounted DMG file. Here are the steps to create it. Step 1: Create a new document in Automator and select Folder Action from the available document types. Step 2: At the top of the right panel, select Other… from the dropdown menu. Then, on the dialog box that pops over, type ~/.Trash to work with that folder. Step 3: Next, on the left panel, drag the Run Shell Script action to the right panel. On the two dropdown menus that show up, select /usr/bin/python and as arguments respectively. Step 4: Replace the placeholder script in the script box with the following one: import string, os, syslines = os.popen(“hdiutil info”).readlines()should_eject = Falsefor line in lines:if line.startswith(“image-alias”):path = line.split(":")[1]image_path = path.lstrip().rstrip()if image_path in sys.argv:should_eject = Trueelif line.startswith("/dev/") and should_eject is True:os.popen(“hdiutil eject %s” % line.split()[0])should_eject = Falseelif line.startswith("###"):should_eject = False Once done, save the Folder Action and quit Automator. Now, whenever a DMG file is mounted, all you’ll have to do is drag it to the Trash and it will be unmounted at the same time. Cool Tip: You can also create keyboard shortcuts for these actions by following the instructions at the end of this tutorial. And there you go. Two different workflows to enable a very convenient feature on your Mac. Now all left to do is just choose which one you find more convenient. And the best of all? In both cases you’ll learn a bit more about Automator. Enjoy! The above article may contain affiliate links which help support Guiding Tech. However, it does not affect our editorial integrity. The content remains unbiased and authentic.

How to Automatically Eject and Delete DMG Files in Mac - 43How to Automatically Eject and Delete DMG Files in Mac - 54How to Automatically Eject and Delete DMG Files in Mac - 79How to Automatically Eject and Delete DMG Files in Mac - 46How to Automatically Eject and Delete DMG Files in Mac - 88How to Automatically Eject and Delete DMG Files in Mac - 6How to Automatically Eject and Delete DMG Files in Mac - 15How to Automatically Eject and Delete DMG Files in Mac - 27How to Automatically Eject and Delete DMG Files in Mac - 55How to Automatically Eject and Delete DMG Files in Mac - 25How to Automatically Eject and Delete DMG Files in Mac - 76How to Automatically Eject and Delete DMG Files in Mac - 43How to Automatically Eject and Delete DMG Files in Mac - 2How to Automatically Eject and Delete DMG Files in Mac - 10How to Automatically Eject and Delete DMG Files in Mac - 50How to Automatically Eject and Delete DMG Files in Mac - 99How to Automatically Eject and Delete DMG Files in Mac - 35How to Automatically Eject and Delete DMG Files in Mac - 56How to Automatically Eject and Delete DMG Files in Mac - 27How to Automatically Eject and Delete DMG Files in Mac - 41How to Automatically Eject and Delete DMG Files in Mac - 33How to Automatically Eject and Delete DMG Files in Mac - 1How to Automatically Eject and Delete DMG Files in Mac - 35How to Automatically Eject and Delete DMG Files in Mac - 7How to Automatically Eject and Delete DMG Files in Mac - 53How to Automatically Eject and Delete DMG Files in Mac - 33