Jump to content
mlondon

Workflow to eject disk image and trash DMG after software install?

Recommended Posts

Wondering if anyone has developed a workflow that can eject a mounted disk image and trash the related DMG after installing software?

Thank you...

 

Share this post


Link to post

Not a workflow, but I did write a Service for that (so you can right-click on the disk image in Finder and do it that way).

 

Here's the Python script. Put this in a Run Script action with Language = /usr/bin/python input as argv:

import sys
import plistlib
from subprocess import Popen, PIPE

path = sys.argv[1]
dmg_path = None
info = Popen(["hdiutil", "info", "-plist"], stdout=PIPE).communicate()[0]
pl = plistlib.readPlistFromString(info)
for image in pl["images"]:
    for ent in image["system-entities"]:
        if ent.get("mount-point") == path:
            dmg_path = image["image-path"]
            break

if dmg_path:
    Popen(["hdiutil", "detach", path])
    Popen(["osascript", "-e", 'tell application "Finder" to delete POSIX file "%s"' % dmg_path])

You'll need to write your own Script Filter to find and list the mounted disk images, and pass the mount point (i.e. /Volumes/NAME) to the script.

Share this post


Link to post
21 hours ago, deanishe said:

Fair enough. This should do the job.

 

I wonder if it's worth releasing properly…

 

 

Thank you deanishe !!!

 

Works perfectly. Yes, why don't you release to the community? 

Happy to donate a little for your time.

Also, as some installers use ZIP instead of DMG, perhaps a way to either accommodate for both DMG & ZIP or a separate workflow for ZIP.

 

Share this post


Link to post
6 minutes ago, mlondon said:

Also, as some installers use ZIP instead of DMG, perhaps a way to either accommodate for both DMG & ZIP or a separate workflow for ZIP.

 

For ZIP files, you could use a standard Alfred File Filter configured to search ~/Downloads for ZIP files and connect that to a Run Script action that deletes/trashes the file.

 

 

Edited by deanishe

Share this post


Link to post
On 02/11/2016 at 12:54 AM, deanishe said:

Fair enough. This should do the job.

 

I wonder if it's worth releasing properly…

Hi @deanishe,

 

I'm highly interested in this workflow as well, but the link is broken. A working one would be very appreciated. Thank you!

Edited by deanishe
fix link

Share this post


Link to post

Thanks @deniashe, it works beautifully.

Is there any way to "inject" this workflow into the normal eject feature?

That means appending the keyword "eject" to this workflow as well, and when a user has both DMGs and volumes mounted, "eject" will list them all, and the subtext for DMGs will also include "... and delete".

Share this post


Link to post
5 hours ago, kodiak said:

Is there any way to "inject" this workflow into the normal eject feature?

 

The only thing you can do is set the workflow and the "eject" feature to use the same keyword. They'll all show up at the same time, but the disk images will be duplicated, and it probably won't work very well.

 

To get a satisfactory experience, Andrew would have to add the "…and trash" feature to Alfred or someone would have to add eject features to this one.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...