How to Empty Trash with ‘rm -rf ~/.Trash/*’ from Finder

findertrash

Sometimes emptying the trash in Finder takes significantly longer than just running rm -rf ~/.Trash. Is there some way to remap the "right click on trash in dock + click to empty trash" button to a script?

Best Answer

It would be easier to use an alias like this:

alias et="(shopt -s nullglob; find ~/.Trash /Volumes/*/.Trashes/501 -mindepth 1 -delete)"

rm -rf ~/.Trash/* doesn't work if the list of filenames is longer than getconf ARG_MAX, and it doesn't include files that start with a period. Deleting files in trash folders often requires root permissions though.

tell app "finder" to empty and trash -e (see hasseg.org/trash) can be run silently or on the background, but they are just as slow as emptying the trash from the GUI, and they make Finder display error dialogs if for example files are in use.