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: lmodern on May 19, '09 03:21:21AM
As this script is very dangerous (I accidentally deleted an important file), I added a "deletion confirmation" dialog box before removing any element.
The new script looks as follows:

set frontAppPath to (path to frontmost application) as string

if the frontAppPath ends with ":Finder.app:" then
	tell application "Finder"
		set selectionList to get selection as list
		set selectedCount to count items in selectionList
		--Added code1
		display dialog "Do you really want to delete this item?" buttons {"OK", "Cancel"} default button 2
		if the button returned of the result is "Cancel" then
			return
		else
                --End of added code1
			if selectedCount > 0 then
				repeat with i from 1 to number of items in the selectionList
					set selectedItem to item i of the selectionList
					set selectedName to the name of selectedItem
					set homePath to (path to home folder) as string
					set trashPath to homePath & ".Trash:"
					set deletePath to trashPath & selectedName & ":"
					
					if not ((kind of selectedItem as string) is equal to "Volume") then
						if (selectedItem as string) contains ".Trash" then
							set posixPath to POSIX path of (selectedItem as string) as string
							do shell script "rm -rf "" & posixPath & """
						else
							try
								deletePath as alias
								display dialog "Error: file named "" & selectedName & "" already exists in the Trash."
							on error
								try
									tell application "Finder" to delete selectedItem
									do shell script "rm -rf ~/.Trash/"" & selectedName & """
								end try
							end try
						end if
					end if
				end repeat
			end if
                 --Added code2		
                 end if
                 --End of added code2
	end tell
end if



[ Reply to This | # ]