Ready! Dave Dribin's 1UP

osx-trash

osx-trash manipulates the Mac OS X trash from the command line, just like the Finder does. It uses AppleScript via Scripting Bridge on top of RubyCocoa to communicate with the Finder. You can move files to the trash, empty the trash, and list items currently in the trash.

osx-trash requires Mac OS X 10.5, Leopard. To install, use the gem command:

% sudo gem install osx-trash

You can also download the gem and other distributions from the RubyForge project page. Online documentation can be found on the RubyForge home page.

The package comes with a command line program called trash. Here’s a simple example:

% touch foo bar baz
% trash -l
% trash foo ba*
% trash -l
/Users/dave/.Trash/foo
/Users/dave/.Trash/bar
/Users/dave/.Trash/baz
% trash -e
% trash -l

Using Finder’s AppleScript has a number of benefits compared to shell scripts that just move files to ~/.Trash. First, it creates unique names when there are collisions:

% touch foo
% trash foo
% touch foo
% trash foo
% trash -l
/Users/dave/.Trash/foo
/Users/dave/.Trash/foo 20-38-20

It also handles trashes on different volumes properly:

% touch foo
% trash foo
% touch /Volumes/DiskImage/bar
% trash /Volumes/DiskImage/bar
% trash -l
/Users/dave/.Trash/foo
/Volumes/DiskImage/.Trashes/501/bar

License

The source code is released under the MIT license.

Contributing

The Git repository is here:

git clone git://rubyforge.org/osx-trash.git
These pages are copyright © 2002-2008 by Dave Dribin. If you have any comments or suggestions, please contact me.