PDA

View Full Version : Batch "Put Back" files from Trash to original location




jozeppy26
Apr 22, 2013, 04:37 PM
Is there anyway to use the native "put back" feature to restore 11,000 items that are currently in the Trash?

Files originated from many different folders throughout the OS. The "Put Back" option in the contextual menu is greyed out unless only 1 file is selected at a time. Has anyone ever tried (and succeeded) at writing something in Automator or an Applescript to batch "put back" each file individually? Or do I really have to use "command + delete" & close the opening folder 11,000 times? My friend is panicking.

I've tried google searching for a repair to this issue, but I only get a bunch of posts from 2010 with people claiming that "Mac's don't put back anything from the trash. Oh wait, I guess I was wrong, it does" but then no one continues to research the issue.



w0lf
Apr 22, 2013, 04:53 PM
Maybe try this?


Finally I managed to restore all my files by writing an AppleScript, which was inspired by this source http://www.giacomoballi.com/applescript.html
The original script did not work for me, as it uses keystrokes on the current finder window. On OS X Lion (I guess also on previous versions) the put back reveals the original location in a new finder window, so subsequent delete keystroke in the repeat cycle would delete a file again.... Anyhow, if anybody finds it useful, I copy it here. Be careful, no warranties so only use it if you know what you're doing. One more sidenote, if your trash contains a file which can not be restored anyhow, you need to skip it somehow when it comes to the top. I had such files, but I did not bother with this too much as I sorted the view by last access time and these files became the last ones in the list. Good luck and keep pokeing Apple to make them provide somehow this trivial feature.


repeat 4173 times --or as many files you have
tell application "Finder" to open trash --open the trash folder
tell application "Finder" to activate
tell application "System Events"
tell process "Finder"
delay 0.2 -- adjust delay as needed
key code 125 --move down to get focus on a file
key down command --hold command key
delay 0.2 -- adjust delay as needed
key code 51 --hit delete
key up command --release command
end tell
end tell
delay 0.2 -- adjust delay as needed
tell application "Finder" to close every window --close everything for the next cycle
end repeat

jozeppy26
Apr 22, 2013, 05:00 PM
that'll do it. I ran into the same issues with the original code, thank goodness there's someone smart enough to fix it. Many thanks to you and OP.

tomtom2
Jul 4, 2013, 10:30 AM
I accidentally deleted 1,057 files. I really need those back in their original location.

I tried to run the script and it is doing something but it doesn't move the files.

Any idea?

Thank you in advance.

canuckuk1
Oct 22, 2013, 12:16 PM
Does ANYONE know how i can put back all the files that have been moved into my trash by mackeeper where they belong...i tried selecting them one bye one and using the put back option but its greyed out!! i have all the files in tact but i dont know where to put them or how to do it...if anyone has any ideas i would greatly appreciate it!!! i tried using the apple script above but it wont work:( im using an imac 10.8.5 and i live in the UK if that helps anyone with an answer for me...HELLLLPPPPPPPPPP PLEASE!!! im loosing my mind my apps and programmes are not working properly coz the files are out of place:(

nxPLQh2SWAjHLnQ
Jan 15, 2014, 05:22 PM
For years all that was required to move files from Trash back to their original locations was to select "Put Back" using "Action" gear icon on command bar.What happened to this option and how can it be retrieved? Requiring an "application" to perform a single function formerly handled by use of the "Action" [gear icon] command is absurd: adds unnecessary complexity, wastes available system space, and ultimately detracts from a certain economic measurement known as Gross Domestic Product[ivity].*