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

Click here to return to the 'Delete files without emptying the Trash' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Delete files without emptying the Trash
Authored by: jdb8167 on Jul 17, '13 02:22:28PM
I did this a while back. I created an automator script which I placed in the services menu which also puts it under the right click menu in the Finder. To create it:

Create an automator script:

Set the "Services receives selected" to "files or folders" in "Finder"

Go to the Library tab and choose Utilities->Run AppleScript

The AppleScript:

on run {input, parameters}
	repeat with anItem in input
		tell application "Finder"
			set itemAlias to anItem as alias
			set i to (info for itemAlias)
			set {kind:itemKind, package folder:packageFolder, name:itemName} to i
			if itemKind = "Folder" then
				set fileList to items of itemAlias
				if (count of fileList) is greater than 0 then
					display dialog "Are you sure you want to delete the folder \"" & itemName & "\" and all of its contents?"
				end if
			else if packageFolder then
				display dialog "Are you sure you want to delete the package folder \"" & itemName & "\""
			end if
		end tell
	end repeat
	return input
end run

Add an "Ask for Confirmation" script:

Title: Delete Item(s) Now?
Subtext: This operation can't be undone

Add a Run Shell Script. Make sure the Shell is set to "/bin/bash"

The bash script:

for file in "$@"
  if [ -f "$file" ]
      rm "$file"
      rm -rf "$file"

This altogether will check to see if an application or non-empty folder is selected and warn before deleting them. It also gives a final chance to stop the delete. If the files selected are not packages (usually applications) or folders, then it only gives the single warning.

Edited on Jul 17, '13 02:24:25PM by jdb8167

[ Reply to This | # ]