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


Click here to return to the 'An AppleScript to empty one user's trash on one drive' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to empty one user's trash on one drive
Authored by: michelle_eris on Mar 13, '07 01:37:59PM

If the trash on the volume is empty, there is an error alert "rm: /Volumes/<disk name>/.Trashes/<uid>/*: No such file or directory"

To fix this problem, modify the code to this:

try
do shell script "rm -r " & trashpath & "*"
end try

I'd also append "giving up after 2" to the second dialog. This will automatically dismiss the dialog after two seconds.



[ Reply to This | # ]
An AppleScript to empty one user's trash on one drive
Authored by: kopf on Mar 13, '07 04:50:32PM

Nice idea!

The droplet could use two improvements:

1. Sanity check to see if anything other than a volume has been dropped. Just use it with any folder on the startup volume and you'll see the problem.

2. Instructions when the application is run instead of something dropped on it.



[ Reply to This | # ]
An AppleScript to empty one user's trash on one drive
Authored by: rolf-thomas on Mar 14, '07 02:05:59AM

I had a whitespace in the drives name and the "rm" doesn't work. I inserted a search-replace to mask whitespaces with backslashes.

Works now as expected. Thank you!

So here is my modification (and german localization :-).

on open dropped_item
	tell application "Finder"
		set drivepath to POSIX path of dropped_item
	end tell
	if drivepath is "/" then
		display dialog "Funktioniert nicht auf dem Startlaufwerk." buttons {"Ok"} default button "Ok"
	else
		set uid to the third word of (do shell script "id")
		set trashpath to drivepath & ".Trashes/" & uid & "/"
		beep
		set confirm to display dialog ¬
			"Mülleimer von " & trashpath & ¬
			" leeren?" buttons {"Nein", "Ja"} default button "Nein"
		if button returned of confirm is "Ja" then
			set trashpath to searchReplace(trashpath, " ", "\\ ")
			try
				do shell script "rm -r " & trashpath & "*"
			end try
			display dialog "Der Mülleimer wurde geleert" buttons {"Ok"} default button "Ok" giving up after 2
		end if
	end if
end open

to searchReplace(thisText, searchTerm, replacement)
	set AppleScript's text item delimiters to searchTerm
	set thisText to thisText's text items
	set AppleScript's text item delimiters to replacement
	set thisText to "" & thisText
	set AppleScript's text item delimiters to {""}
	return thisText
end searchReplace[code]


[ Reply to This | # ]