Eject and delete DMGs in one strike
Opening a downloaded .dmg
file goes fairly quick, straight from the browser. Unmounting it, once the .app is copied to the applications folder, also goes pretty quick using CMD+E
. But then, there's still that dmg file in the downloads folder, forcing you to navigate there in Finder and manually deleting it.
Not when you have CMD+SHIFT+E
linked to this AppleScript, set up as an Automator Service for Finder!
1. Create a new Service in Automator
no input
in Finder.app
2. Service receives Run AppleScript
block
3. Drag in a new 4. Paste in the code
tell application "Finder"
set my_selection to (target of front Finder window)
set my_name to name of my_selection
set 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 false
repeat with v from 1 to (count volume_list)
if "/Volumes/" & my_name = item v of volume_list then
set match_found to true
exit repeat
end if
end repeat
if match_found is not equal to true then
display 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 1
return
else
set my_source to POSIX file (item v of source_list) as alias
eject my_name
move my_source to the trash
end if
end tell