Folder actions... find original path of files?

I’ve figured out the basic for Folder Action scripts. I wrote a script that prints out a list of the files that are moved to a folder. It works fine. However, what I’ve been trying to figure out for the last week is how to get the original paths of the files before they were put into the folder. I can’t seem to figure this out. Is it possible to do this with folder actions? Or, can I somehow attach the script to the Finder and intercept it’s events?

Could you maybe just write a droplet app that you drop the files onto and then it does the report and then moves the files to the new folder? You wouldn’t need any folder actions.

Nope, needs to be a folder action because I want to attach it to the trash folder. Otherwise I’d just write a program. :slight_smile:


There might be a way to do this by using the Finder Undo. I’m trying it now.



I have a feeling that this fa script shouldn’t work this way because the items are being added back to the folder, but here’s a test folder action script:

on adding folder items to this_folder after receiving these_items
– may not need this whole section as is
tell application “Finder” to activate
tell application “System Events”
tell process “Finder”
keystroke “z” with command down
end tell
end tell
delay 1 – may not need this also
– end may not need
set original_paths to {}
repeat with this_item in these_items
set end of original_paths to ((contents of this_item) as string)
end repeat
tell application “Finder”
move these_items to this_folder
end tell
choose from list original_paths
end adding folder items to

Make a folder somewhere, attach this fa, and test it by adding a couple of files to the folder. The folder action worked here in Jaguar, but in Panther, change ‘with command down’ to ‘using command down’

BTW, I don’t think you can attach a folder action to the trash in OSX.

Need food.


Thanks for the script! I haven’t tested it yet… but that’s like what I was trying to do. I had the brainstorm that I could keep the alias of the files dragged to the folder, do a Finder Undo, store the paths and then re-move them to the trash. But I couldn’t figure out how to perform an undo. :slight_smile:

You can assign the action to the trash… ~/.Trash. It’s just invisible.

Again, thanks for the suggestions.

OK, I just tested it and it works perfectly. Thanks a lot! I wasn’t aware that you could send shortcut keystrokes to apps. That comes in handy to know.