This article is about How to Delete DMG Files Automatically on Mac. So read this free guide, How to Delete DMG Files Automatically on Mac step by step. If you have query related to same article you may contact us.
How to Delete DMG Files Automatically on Mac – Guide
One of the aspects where Macs differ most from Windows PCs is when it comes to installing applications. On Macs, you need to mount a disk image and then unmount and delete it when the installation is complete, which can be a bit of a hassle, especially if you have to test many applications in a short period of time .
With that in mind, this time we will share some small workflows that you can implement on your Mac using Automator. With any of them, whenever you finish installing an application on your Mac, you will be able to eject / unmount and delete the disc image with just a few clicks.
Let’s start with how to to define up these great Automator workflows.back to menu ↑
Automatically delete DMG files when you eject them
Step 1: Open Automator and choose to create a new document. Of the types of documents available that show up in the dialog box, select Service.
Step 2: At the top of the right panel, make sure to choose from the drop-down menus the options ‘no entry’ and ‘Finder’ respectively so that the result final either as illustrated below.
Step 3: Then, in the left panel of Automator, look 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 this code and copy and paste the following into the script box instead:
tell the “Finder” application to set the selection list to select if (count selection list) displays the dialog box ¬ “Select a mounted volume from a disk image.” with title ¬ “No selection found” with stop icon ¬buttons pattern button Return ifset my_selection for item 1 from selection_listset my_kind to kind of my_selectionset my_name to name of my_selection if my_kind is not “Volume” in the display dialog ¬ “Select a mounted volume from a disk image file.” with the title ¬ “The selection is not a disk image” with the stop icon ¬buttons pattern button 1return volume_list ifset for paragraphs (shell script “hdiutil info | grep ^ / dev / disk | grep -o ‘/Volumes/.*’▪)set source_list for paragraphs (shell script“ hdiutil info | grep ^ image’ -‘alias | grep -o ‘/.*’icando)set match_found to falserepeat v from 1 to (count volume_list) if “/ Volumes /” & my_name = item v from volume_list thenset match_found to trueexit repeatend ifend repeat if match_found is equal to true; the display dialog ¬ “The selected volume does not appear to be a disk image.” with the title ¬ “The disk image could not be found” with the stop icon ¬buttons pattern button 1returnelseset my_source to POSIX file (item v of source_list) as aliasmove my_source for 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 need to do is select it and in the Finder menu select Services and then Eject and Delete (or whatever name you have named for the service you just created) and the disk image file will be unmounted and deleted with one click.
Now, let’s take a look at another Automator workflow that achieves the same goal by doing the exact opposite.back to menu ↑
Eject DMG files automatically by dragging them to the trash
As you can see in the title, this Automator workflow allows you to achieve the same purpose, except to the contrary, so you can avoid this message whenever you drag a mounted DMG file to the trash.
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 drop-down menu. Then, in the dialog box that appears, type ~ / .Trash to work with that folder.
Step 3: Then, in the left pane, drag the Run Shell Script action to the right pane. In the two drop-down 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:
import string, os, syslines = os.popen (“hdiutil info”). readlines () should_eject = False for the line in lines: if line.startswith (“image-alias”): path = line.split (“:”)image_path = path.lstrip (). rstrip () if image_path in sys.argv: should_eject = Trueelif line.startswith (“/ dev /”) and should_eject for True: os.popen (“hdiutil eject% s”% line.split ()) should_eject = Falseelif line.startswith (“###”): should_eject = False
Once this is done, save the folder action and close Automator. Now, whenever a DMG file is mounted, all you have to do is drag it to the Trash and it will be unmounted at the same time.
Nice Tip: You can also create keyboard shortcuts for these actions by following the instructions in the final this tutorial.
And there it is. Two different workflows to enable a very convenient process feature on your Mac. Now all that’s left to do is choose which one you find most convenient. And the best of all? In both cases, you will learn a little more about Automator. Enjoy!back to menu ↑
I hope you like the guide How to Delete DMG Files Automatically on Mac. In case if you have any query regards this article you may ask us. Also, please share your love by sharing this article with your friends.