12

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?

Hennes
  • 65,804
  • 7
  • 115
  • 169
xdazz
  • 253
  • 1
  • 4
  • 9

5 Answers5

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

valenok
  • 141
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
Lri
  • 42,502
  • 8
  • 126
  • 159
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

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

-1

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.

Canadian Luke
  • 24,640
A C
  • 9