Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I accidentally moved over 4,000 files to the trash, and I want to move the files back to their original locations. While the Lion supports this feature (via the Finder's "Put Back" command), it will only allow you to Put Back one file at a time.

I found an AppleScript script to automate the process of Putting Back files one file at a time. I ran the script overnight and it mostly worked, but 1,700 files remained in my trash.

The problem is the remaining files require me to enter a password before the Put Back can take place. I believe these files were created under a different owner.

My question is how can I get around this?

Is there a way to enter a superuser mode that eliminates me having to enter a password for every file I want to undelete?

Any help is greatly appreciated.

Here is the AppleScript:

  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
share|improve this question
Put Back should be available when multiple files are selected unless the selection contains files that don't support it. Can you link to the AppleScript? – user495470 Jul 19 '12 at 17:33
If the files were deleted from the same folder then the OS allows you to put multiple files back. However I have files from all over the place. I've included the script in my question. – computergeek Jul 19 '12 at 17:41
I'm mentioning it here as well, but the question was cross-posted at Ask Different and Stack Overflow – user495470 Jul 20 '12 at 17:44
up vote 1 down vote accepted

You could also emulate typing the password. The keystroke "password" & return part should be harmless when a password dialog is not shown. I only tested this script with a few files, so it might still need to be modified.

tell application "Finder"
    repeat 4 times
        close windows
        open trash
        tell application "System Events"
            key code 125
            key code 51 using command down
            delay 0.2
            keystroke "password" & return
            delay 0.2
        end tell
    end repeat
    close windows
end tell

I also tried opening Finder as root with sudo /System/Library/CoreServices/, but the put back actions didn't seem to be available for any files.

share|improve this answer

Your Answer


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.