How to restore all the files from trash in Mac OS X?
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?
25 Answers
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:
To run, download script, start terminal and type perl restore_mac_trash.pl
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 repeatYou 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 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.
'Put Back' multiple items in Trash
2Select 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.