11

I can put back the items one by one, but there are too many files, how could I restore all the files in the trash?

3

MacOS keeps file meta information about deleted files in ~/.Trash/.DS_Store, which also contains records of the original locations. I've written a perl script that scans ~/.Trash/.DS_Store file and prints commands to move all files back to their original location. The output can be fed directly to shell.

Perl script: https://gist.github.com/cpq/3d58e144a3fc2e47c54a

To run, download script, start terminal and type perl restore_mac_trash.pl

  • Wow, this was the only option that worked for me! Thanks – Andre Soares Jan 12 '16 at 10:50
2

Here is another AppleScript like the one posted by user227282:

repeat
    tell application "Finder"
        close windows
        if items of trash is {} then return
        open trash
        activate
    end tell
    tell application "System Events"
        key code 125 -- down arrow
        key code 51 using command down -- command-delete
    end tell
end repeat

You can run the script by pasting it to AppleScript Editor and pressing command-R. I didn't need any delays.

If Finder shows a password dialog when it tries to put back some item, try adding something like this to the end of the tell application "System Events" block:

delay 1
if exists window 1 of process "SecurityAgent" then
    tell window 1 of process "SecurityAgent"
        set value of text field 2 of scroll area 1 of group 1 to "pa55word"
        click button 2 of group 2
    end tell
end if
delay 1
0

If it is the last thing you did in the Finder, then using "Undo" would be the preferred method.

There is no built-in way within the GUI to perform the action you are discussing.

This is all assuming that you have not emptied the Trash.

0

Select all the files you want to put back - Apple Key+A for Select All, then right-click over an item and select Put Back. This will put back multiple items at a time.

  • 5
    When you selected all, the Put Back menu will disappear. – xdazz Oct 15 '12 at 15:41
  • I'm on OS X 10.7.5 and it shows for me. Try it - select all the files in the trash and right click, "Put Back" is there. – A C Oct 15 '12 at 16:08
  • 4
    It will work if (and only if) all the files are from the exact same folder. Try deleting files from different sources – it won't work. i.stack.imgur.com/q56wI.png – slhck Oct 15 '12 at 16:10
  • True - you are right. I should have tried more variations. Thanks. – A C Oct 15 '12 at 16:13
0

'Put Back' multiple items in Trash https://gist.github.com/faresd/5661253

  • 2
    This looks a little hacky. Could you explain what the script does, for a little more context? That'd be much appreciated. – slhck May 28 '13 at 8:33
  • 2
    From what I can see, the script tries to close Finder until it is closed, then it reopens it to the trash and puts back the first item in there. After that, it closes all the windows, and repeats. This script uses System Events, which is a very high level of doing something with an AppleScript (it'd be better to do something without taking over the computer interface). If I were the answerer, I would look for a lower-level solution to contribute. – Carter Pape May 28 '13 at 13:43

protected by Community Oct 25 '16 at 5:00

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

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