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


Click here to return to the 'Permanently delete files via AppleScript' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Permanently delete files via AppleScript
Authored by: tedw on May 20, '09 12:51:01AM
this code is far too complex; simpler is (almost) always better
If you want to do this with applescript, use the following:
tell application "Finder"
	if frontmost is false then return
	set selectedList to the selection
	set deleteList to {}
	repeat with thisItem in selectedList
		if class of thisItem is not disk then
			set end of deleteList to thisItem
		end if
	end repeat
	delete deleteList
	ignoring application responses -- because secure deletes can take a while
		empty trash with security
	end ignoring
end tell

if you want to do it with shell scripting, use this:
tell application "Finder"
	if frontmost is false then return
	set selectedList to the selection
	set deleteCmdList to {}
	repeat with thisItem in selectedList
		if class of thisItem is not disk then
			set end of deleteCmdList to quoted form of (POSIX path of (thisItem as alias))
		end if
	end repeat
end tell

set {tid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, " "}
set cmd to deleteCmdList as text
set AppleScript's text item delimiters to tid
do shell script cmd

I'd also suggest you do what I do in my own secure delete script: run the delete list through a choose from list alert so that you can check and remove anything you don't want to destroy.

[ Reply to This | # ]
oops - an error
Authored by: tedw on May 20, '09 08:43:56AM
this line in the second script - set deleteCmdList to {} - should actually read like this - set deleteCmdList to {"srm", "-rfmz"}. The script won't do much if you don't specify the unix command. :)

[ Reply to This | # ]