Another AppleScript to re-create the desktop trash

Mar 22, '04 09:47:00AM

Contributed by: Anonymous

This is an AppleScript droplet I've been using to reproduce the trash icon functionality on my desktop, like on old-style Macs. Why? Because you're never sure where the trash icon is going to be on your screen in the OSX dock -- it jumps about, if you have a lot of apps open, it will be in one corner, if not, it will be closer to the middle. I'm not the only one with this peeve.

Like the normal trash icon, and unlike other ways of doing the same thing, this script can trash files on any attached disks, and you can also drag disks to it to unmount them. Double-clicking it lists the contents of the trash. I've only tried this on 10.3. Others have written similar scripts, but I haven't seen the source.

To hide the icon from the dock when it runs, you need to save the script as an application bundle. If you want to be even more old-school, you can give this droplet an icon from /System -> Library -> CoreServices -> SystemIcons.bundle -> Contents -> Resources -> TrashIcon.icns.

on run
  tell application "Finder"
    if Finder window "Trash" exists then
      open window "Trash"
    else
      make new Finder window to trash
    end if
  end tell
end run
	
on open these_items
  repeat with i from 1 to the count of these_items
    set this_item to (item i of these_items) as alias
    set this_info to info for this_item
    tell application "Finder"
      try
        eject this_item
        delete this_item
      end try
    end tell
  end repeat
end open
Bug: aliases can't be trashed unless they're in folders. If anyone knows why I'd love to know.

[robg adds: I tested the script, and it works as described on files, folders, and disks. Personally, I only trash things via Command-Delete or (rarely) the Delete icon on the Finder toolbar. There are also third-party solutions, such as Drag Thing, that will enable the desktop trash, but this script is both free and effective.]

Comments (5)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20040316161400957