Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to empty the trash as root System
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?]
    •    
  • Currently 1.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[9,497 views]  

An AppleScript to empty the trash as root | 6 comments | Create New Account
Click here to return to the 'An AppleScript to empty the trash as root' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
"Save as Run-Only" not totally secure.
Authored by: lazymutt on Apr 12, '02 10:21:42AM

While you can save a script as "Run-Only" in the Script Editor, and remove
the ability to edit the script. If you drop the script on a resource editor the
strings are visible for anyone to see. Check the "scpt" resource.

Wouldn't do this with my admin password.



[ Reply to This | # ]
a better way
Authored by: mkoz on Apr 12, '02 10:49:53AM
from the "Standard Additions Dictionary":
do shell script: execute a shell script or command
	do shell script  plain text  -- the command or shell script to 
		execute.  Examples are ‘ls' or ‘/bin/ps -auxwww'
		[administrator privileges  boolean]  -- execute the command 
			as the administrator
		[password  plain text]  -- use this administrator password 
			to avoid a password dialog
	[Result:   plain text]  -- the command output

if you notice you can leave out the password and you will be prompted for an administrator password.

so with that information we can make some slight changes to the script, with no stored password.

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 
		"rm -rf /.Trashes/*  ~/.Trashes/*  ~/.Trash/*" 
		with administrator privileges
	--"/Volumes/*/.Trashes/*"
end if


[ Reply to This | # ]
a better way
Authored by: dev909 on Apr 12, '02 11:39:44AM

thanks mkoz!
I already changed that but I didn't post...



[ Reply to This | # ]
Empty Trash as Root
Authored by: jayk6 on May 26, '02 03:01:57PM

When using the" Applescript to empty the trash as root.", how do you transfer files into the trash? In the /var/log/ folder, attempting to put archived files in the trash is not allowed except in root. Do you activate his script first then go to the log folder and add items to the trash?



[ Reply to This | # ]
Trash Can still looks full (This is the fix)
Authored by: applecompsrule on Jun 21, '02 07:25:07PM


I noticed that when I used the applescript to empty the trash that the trash can icon still appear full. To fix this I simply add this to the end of the script:


tell application "Finder"
empty
end tell



This tells the Finder to empty the trash and makes the trash can look empty.

[ Reply to This | # ]

Trash Can still looks full (This is the fix)
Authored by: Mr Tea on Feb 12, '03 05:23:57PM

But... the empty command can sometimes display a progress bar even after the shell scripts have run.

Instead, conclude the script with this line:

tell application "Finder" to update the trash.


Regards,

Mr Tea



[ Reply to This | # ]