Fast trash emptying via Unix script turned into an app

Jul 21, '09 07:30:00AM

Contributed by: lanny

I was tired waiting for the Finder to prepare the Trash emptying and then watching it delete the stuff one by one. So I wrote the shell script below, used Platypus to make an app, and have it on my desktop for single-click, fast trash emptying.

#/bin/sh
cd ~/.Trash
dirs=`find ~/.Trash -type d | wc -l`
fils=`find ~/.Trash -type f | wc -l`
byts=`du | tail -1`
(( dirs = dirs -1 ))
echo "$dirs: directories"
echo "$fils: files "  
echo "$byts: bytes "   

rm -Rf ~/.Trash/*
echo Return code: $?
To try, you can open an empty file in a text editor, copy the code, and save the file (i.e cleantrash.sh) on your Desktop. Then control-click and choose Open With from the conextual menu, and select Terminal from the list of apps.

[robg adds: I tested this one, and it worked as described. For more on Platypus, see this older hint. (The URL for the app has changed, though, so use the link above in this hint. Finally, this previous hint covered emptying the trash via script in a somewhat different manner. Check your trash before testing this script, just in case there's something there you really want -- it'll be gone for good once you run the script.]

Comments (15)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20090713161927884