A while ago, I used to have some kind of App or service that would automatically unmount a dmg file whenever I put the dmg file into the trash. This was really convenient, but I've since reinstalled OS X, and I've completely forgotten the name of the app that provides this useful feature. I still have backups of my old system, but I have no idea where to look. So, does anyone know of an app that provides this feature?

(Note: There are plentiful tutorials on how to achieve the reverse, i.e. auto-trash on eject, but this is not what I'm looking for.)

1 Answer 1


I found two options

  • Use a folder action on ~/.Trash to unmount any DMG getting moved into the trash can (see second part of this article, summarized below)
  • DMG Cleaner claims to be able to do this as well

Folder Action to unmount DMG moved to Trash

  1. Create a new "Folder Action" workflow in Automator
  2. Set Folder Action to work on ~/.Trash
  3. Add a "Run Shell Script" action to the workflow
  4. Set shell to "/usr/bin/python" and make sure input gets passed as arguments
  5. Replace the content of the script box with the following script

    import string, os, sys
    lines = os.popen("hdiutil info").readlines()
    should_eject = False
    for 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 = True
        elif line.startswith("/dev/") and should_eject is True:
            os.popen("hdiutil eject %s" % line.split()[0])
            should_eject = False
        elif line.startswith("###"):
            should_eject = False
  6. Save the workflow

  • Thanks, I think this folder action was probably the solution I was using before! Dec 6, 2015 at 16:21
  • I can confirm this still works on macOS Sierra 10.12.2. Thank you so much! This is a must-have workflow for me. Jan 17, 2017 at 13:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .