An AppleScript to empty the trash as root

Apr 12, '02 07:43:02AM

Contributed by: Anonymous

Here's a nice way to get rid of all those files in trash that you don't have permission to modify. Paste this text into Script Editor, change the second line from "xxxxxxxx" to your admin password, and save as an application:

-- emptytrashX 0.1
-- 2002 devils@pobox.com
-- set your admin password inside the quotes
set swordfish to "xxxxxxxx"
display dialog "Empty Trash as root?" buttons ¬
{"Cancel", "TRASH"} default button "TRASH" with icon note
set the user_choice to the button returned of the result
if the user_choice is "Trash" then
display dialog "ARE YOU SURE?" buttons {"NO", "YES"} ¬
default button "NO" with icon note
set the user_choice to the button returned of the result
end if
if the user_choice is "Yes" then
do shell script "sudo rm -rf /.Trashes/*" password swordfish ¬
with administrator privileges
do shell script "sudo rm -rf ~/.Trashes/*" password swordfish with ¬
administrator privileges
do shell script "sudo rm -rf ~/.Trash/*" password swordfish ¬
with administrator privileges
--do shell script "sudo rm -rf /Volumes/*/.Trashes/*" password ¬
swordfish with administrator privileges
end if
Then just double-click to use root power to empty all your trashes.

[Editor's note: I haven't tried this yet, but the actual "sudo" commands as listed are what I use at the command line to force a trash can to empty. Also note that having an AppleScript lying around with your admin password in it could be considered something of a security hole -- a quick drag and drop onto Script Editor, and your admin password is revealed. Perhaps a modification to the script to request the password prior to proceeding instead?]

Comments (6)


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