Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Snow Leopard allows users to "Put Back" files that were moved to the Trash from Finder. However, when I do mv <file> ~/.Trash from the command line I don't get the "Put Back" option.

Is there a native command in Snow Leopard that moves a file to the trash while letting me still be able to us "Put Back"?

share|improve this question

5 Answers 5

up vote 3 down vote accepted

When you move a file to the trash OS X updates the .DS_Store file inside ~/.Trash with the "Put back" information. (See this question for more details)

In order to update this you would have to also update the .DS_Store file when you move a file to the Trash in Terminal.

share|improve this answer
    
Thanks. Not what I was hoping for, but it's the truth. –  sirlancelot Mar 5 '10 at 21:58

You want the rmtrash program.

You can use it to add items to the Trash as if it was done in the finder.

Edit: I just tried using rmtrash to delete and recover. It works exactly like deleting from finder. Files show up in the Trash, can be dragged out and emptied exactly the same. Been using it since '06 or so.

share|improve this answer
    
From the code of rmtrash, it looks like it is just equivalent to mv file ~/.Trash/. Are you sure that you can recover the files from this tool? –  Albert Jun 4 '12 at 19:25

I recommend installing the Ruby gem osx-trash.

How?

sudo gem install osx-trash

Usage?

Usage: trash [OPTIONS] <file> [<file> ...]
       trash [-e | --empty]
       trash [-l | --list]
Specific options:
    -e, --empty                      Empty the trash
    -l, --list                       List items in the trash
    -h, --help                       Show this message
    -v, --version                    Show version

Manipulate to the Finder's trash.
share|improve this answer
1  
Nice! Though, as it communicates with Finder, trashing files with a wildcard plays the trashing sound for every file. –  koiyu Mar 20 '11 at 17:59
    
I don't think this still works. From the docs: osx-trash requires Mac OS X 10.5, Leopard. I tried it and all I get is bash: trash: command not found –  yourfriendzak Aug 23 '13 at 2:46
    
Doesnt work on OS X 10.9 asked a fresh question about how to fix it here superuser.com/questions/694433/… –  simbo1905 Dec 29 '13 at 9:35

In the MacOSX SDK, there are the functions FSPathMoveObjectToTrashSync and related. It should be easy to write a Python (or whatever) script around it.

Edit: Just coded it. Can be found here: rm-trash.py.

share|improve this answer
    
FYI - FSPathMoveObjectToTrashSync is deprecated in 10.8 and according to the doc you will need to use trashItemAtURL:resultingItemURL:error: instead. –  Lester Cheung Jan 10 '13 at 23:05

After looking at the alternatives I found out that:

  • The rmtrash program moves files to the trash directory without using the system API, so the .DS_Store file won't be updated. Also, doesn't trigger the recycle sound.
  • The python script invokes a deprecated method on mountain lion which also doesn't trigger the recycle sound.
  • The ruby script works, but is sloooooow (like the python one).

So I wrote my own trash command implemented in the Nimrod programming language, so its fast and it triggers the trashcan sound in a background process. This means that typing the command and running it exits immediately as it doesn't need to wait for the sound to play. The con is you need to compile nimrod and then this program (no binary sorry!).

PS: To be honest the best implementation would be that of rmtrash using the official API I'm using from Nimrod, which is plain objective-c.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.