2

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?

2

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

  • 1
    Thanks for the response. As I mentioned in my post I've tried this method of using Automator Workflows or Applescript Scripts as Folder Actions. If I was to drop a file into the folder it works correctly. However if the application creates a file, the folder action never triggers. – s1rc Mar 21 '15 at 20:23
2

I have a feeling that what ever you try will not register the files before the app can delete them if your saying it is already too fast.

But you could look at launchAgents/Daemons

launchAgents/Daemons

Many kinds of tasks that do not require user interaction are most effectively handled by a process that runs in the background. You can use a daemon or service to:

  • Provide server functionality, such serving web pages.
  • Coordinate access to of a shared resource, such as a database.
  • Perform work for a foreground application, such as file system access.

Apple provide a comprehensive guide here

You should be able to create one and watch the folder with it. The Launch agent can run commands and scripts which you add to its Program Arguments.

  • Sorry for the delay in responding. Finally had a chance to look into this. I created a launch agent to run an sh script to move the files, looks like it still takes about 5 seconds for it to be triggered from the watch directory. Now I’m looking into how to speed this up. However I have a feeling it might not be possible. I may be out of luck when it comes to being able to debug these files. – s1rc Mar 26 '15 at 17:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .