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: 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 | # ]