mlondon Posted November 1, 2016 Share Posted November 1, 2016 Wondering if anyone has developed a workflow that can eject a mounted disk image and trash the related DMG after installing software? Thank you... Link to comment
deanishe Posted November 1, 2016 Share Posted November 1, 2016 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. Link to comment
mlondon Posted November 1, 2016 Author Share Posted November 1, 2016 Hi Deanise, Very kind of you. However I have no idea how to "write your own Script Filter to find and list the mounted disk images" !!! Link to comment
deanishe Posted November 1, 2016 Share Posted November 1, 2016 (edited) Fair enough. This should do the job. I wonder if it's worth releasing properly… Edited March 2, 2018 by deanishe fix link Link to comment
flome Posted November 2, 2016 Share Posted November 2, 2016 (edited) 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… I just came across this. Should come in very handy, thank you! Edited March 2, 2018 by deanishe fix link Link to comment
mlondon Posted November 2, 2016 Author Share Posted November 2, 2016 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. Link to comment
deanishe Posted November 2, 2016 Share Posted November 2, 2016 (edited) 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 November 2, 2016 by deanishe Link to comment
kodiak Posted March 2, 2018 Share Posted March 2, 2018 (edited) 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 March 2, 2018 by deanishe fix link deanishe 1 Link to comment
deanishe Posted March 2, 2018 Share Posted March 2, 2018 (edited) Here you go. Thanks for spotting that. I've updated all the links on the page. Edited March 2, 2018 by deanishe kodiak 1 Link to comment
rebdeg Posted March 4, 2018 Share Posted March 4, 2018 Thanks @deanishe just what I needed! Link to comment
kodiak Posted March 4, 2018 Share Posted March 4, 2018 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". Link to comment
deanishe Posted March 4, 2018 Share Posted March 4, 2018 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. Link to comment
noisyneil Posted June 30, 2021 Share Posted June 30, 2021 (edited) This is very handy. I don't know anything about scripting, but I'm wondering if it would be a simple thing to create a version of that script that does the following: Ejects all disk images (not disks). That's it. No selecting, no trashing, just a one-button disk image ejector. Failing that, I presume that deleting the second half of your script will do the ejecting part without the trashing part, as so: log() { echo "$@" >/dev/stderr } log "name=$dmgname, mount=$dmgmount, path=$dmgpath" # unmount out="$( hdiutil detach "$dmgmount" 2>&1 )" hds=$? if [[ $hds -ne 0 ]]; then log "hdiutil exit status: $hds" log "$out" echo "$out" exit 1 fi Edited June 30, 2021 by noisyneil Link to comment
vitor Posted March 30, 2022 Share Posted March 30, 2022 (edited) @deanishe This one was easily converted to Python 3. Since there’s no public repo to submit a PR, added to my list of requested Workflows (direct download). Edited October 11, 2022 by vitor Link to comment
odapg Posted October 11, 2022 Share Posted October 11, 2022 Hi @vitor, the above link seems broken. Do you think you could give another one? Thanks! Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now