Automatically Move Files Created In Folder

finderscript

I have a project I've inherited from an ex-employee that is missing the source, so I am attempting to debug from the temp files it creates in a directory. The issue is that it creates and deletes some of these files so quickly I cannot move them to another folder.

I've tried AppleScript or Automator to automatically move files, however it doesn't seem to work on files created by the app, but does work if I move files into the directory in Finder.

I've also tried a looping shell script that does a mv *, but it also doesn't catch all files.

Is there some other way to automatically move files to another directory before they are deleted, or prevent the files from being deleted in the first place?

Best Answer

Try using a feature of OS X called "Folder Actions".

Right click on any folder and select "Folder Actions Setup".

It will gives you a whole list of options. These options come with the operating system. If you would like to modify a script you can double click it and make a duplicate. You can edit your script to do what ever you want. For example, I could code the script so that once an item has been added to the folder, it would play a sound or send me an email. It's quite useful.

Once you have coded your script you need to move it to the correct path. Go to Finder and select "Go", then press "Go to Folder". Type in this path: /Library/Scripts/Folder Action Scripts/. Drag and drop your script to that folder. You may be prompted for a password.

Next, go to the folder that you want the script to be applied to. Right click and your new script should be listed. Select it and hit Attach.

There you go!

Hope this helps.

More Information on Folder Actions here