Wishful Coding

Didn't you ever wish your
computer understood you?

A better Trash for Mac

Different at least... I bothers me that the Mac Trash leaves hidden .Trash folders everywhere, including external drives. I wrote a few AppleScripts to move all Trash in one place and delete files completely. If you only want to remove trash from external drives, see my earlier post. This approach is still far from ideal, but it's interesting and it might inspire someone to do a better job than I did. The idea is to move files to a sparse image and delete that image when you need to empty the Trash. You can do this with Disk Utility and a bit of AppleScript.

A better Trash for Mac

To create the image, open Disk Utility in /Applications/Utilities, click New Image and create a Sparse Image.

A better Trash for MacI think it is nice to make the image a Stationary Pad, so you get a new Trash can every day for easier selective deletion. To do this, select the image and press CMD+i and select Stationary Pad. Now all that remains are the AppleScripts. Save those as Application Bundles named Trash and Delete respectively.
property image : POSIX file "/Users/pepijndevos/Trash/Trash.sparseimage" -- edit this
property mount : POSIX file "/Volumes/Trash" -- and this

tell application "Finder"
        if not (exists mount) then
                open image
                delay 5
        end if
        open mount
end tell

on open the_files
        tell application "Finder"
                if not (exists mount) then
                        open image
                        delay 5
                end if
                repeat with the_file in the_files
                        do shell script "mv -f " & quoted form of POSIX path of the_file & " " & quoted form of POSIX path of mount
                end repeat
        end tell
end open
on open the_files
        repeat with the_file in the_files
                do shell script "rm -rf " & quoted form of POSIX path of the_file
        end repeat
end open
A better Trash for MacNow drag these to the Dock for easy access to the Trash and Delete functions. You can just drag files on them to trash or delete them. Another option of course is to have only the Delete script and a regular folder in your Dock, but that is not half as fun, is it?
Published on