Cyan Canyon
Great Circle DistancesSkipping the Mac TrashFooBrain Help FilesFooBrain v1.0 ReleasedAAAA for iPodA Different Way to GetFiles
Skipping the Mac Trash
June 10, 2008

As much as I think that Mac OS X is a generally superior operating system, there is a thing or two that I gripe about. One is the Windows luxury of being able to yank out my USB key at any random time and without any prerequisite action, but I'm not going to talk about that one today. Another is the lack of a skip-the-trash delete command similar to shift-delete in Windows.

I know its easy to send something to the trash and then empty the trash and people have even automated this, but its not what I'm looking for. I want to completely delete a file without also deleting everything that just happened to be in the trash too. I also want to do it with a keyboard shortcut, but I haven't gotten there yet.

Here is my dock...

dock with toilet next to trash

Oh yeah, theres a toilet on my dock. Drag a file to the trash and it gets marked for deletion. Drag it to the toilet, and you get...

delete notification

This is done with some AppleScript which calls some shell script together with configurable folder actions.

NOTE: This is all done on OS X Tiger, please let me know if there are caveats for (Snow)?Leopard.

The UI is just a folder where the icon has been set to the toilet pic. Then it is dragged down into the dock for easy access.

Next there is the AppleScript. This routine gets the list of files in a directory. For each file, it checks to make sure its not the .DS_Store or the icon file and if not, calls the shell command to delete it.

on adding folder items to this_folder after receiving these_items
  set the item_count to the count of these_items

  --confirm the deletion
  set the_choice to display dialog (item_count as string) & " items are set to be deleted." buttons {"Delete", "Move to Trash"} default button 1
  set the_result to button returned of the_choice
  if the the_result is equal to "Delete" then
    repeat with filename in these_items

      --don't process the .DS_Store or the icon file
      if ((filename as string) ends with ":.DS_Store") or ((filename as string) ends with ":Icon") or ((filename as string) ends with ":Icon ") then
        --do nothing
      else
        try
          --the delimiter is a colon, so we have to replace it with a slash so the shell command can read it
          set tid to text item delimiters
          set new_filename to missing value
          set text item delimiters to {":"}
          set fnstring to text items of (filename as text)
          set text item delimiters to {"/"}
          if last item of fnstring is equal to "" then
            set new_filename to "/" & ((items 2 thru -2 of fnstring) as string)
          else
            set new_filename to "/" & ((items 2 thru -1 of fnstring) as string)
          end if
          set text item delimiters to tid
        on error msg
          display dialog msg
        end try

        --call the shell command
        --the 'r' flag indicates that if the pathname points to a directory, it should be deleted as well as all files and folders it contains
        --the 'f' flag indicates that the deletion is forced, nonexistent files are ignored and there are no prompts
        do shell script "rm -rf \"" & new_filename & "\""
      end if
    end repeat
  else
    --If you changed your mind, move it to the trash where it will be recoverable
    tell application "Finder" to delete these_items
  end if
end adding folder items to

And then we just attach the script as a folder action to the toilet folder. Then, any time files are added to the folder (for example, by dragging them onto the dock icon) the script is fired off and the files deleted.