ThomasReggi
ThomasReggi

Reputation: 59345

Applescript folder actions support for changed / altered / updated files?

Does the folder action for when a folder item is changed not exist? I want my script to run when and if I update a file. I don't see any reference to it in the documentation. Is there some sort of alternative I am missing because this seams pretty crazy to not have.

on adding folder items to this_folder after receiving added_files
    do shell script "anything"
end adding folder items to

on removing folder items from this_folder after losing removed_files
    do shell script "anything"
end removing folder items from

-- does not exits?!?
on changing folder items in this_folder after updating changed_files
    do shell script "anything"
end changing folder items in

Upvotes: 3

Views: 3471

Answers (4)

Paul
Paul

Reputation: 1545

I found a tricky way to do this with Automator easily and works only in some cases so try it and see if it helps. When you create/modify a folders contents in OSX a hidden OS file called .DS_Store gets written to the folder, its a useless file to a user but it can trigger the folder action. With that said, I use rsync in a Run Shell Script action in my folder action. Once the action is done syncing I then remove the .DS_Store file.

Here is my example:

rsync -r /Users/path/to/source/* /Users/path/to/destination
rm -f /Users/path/to/source/.DS_Store

Then the next time you modify files/folders in that directory, the folder action kicks in and the process would repeat.

I hope this helps...

Upvotes: 1

Giovanni Massaro
Giovanni Massaro

Reputation: 53

What about rsync -va '/source/path/' '/destination/path/', using Lingon, have this simple command set as an user Daemon to run, say, every 10 sec?

Upvotes: 1

regulus6633
regulus6633

Reputation: 19032

There is an alternative to folder actions. You use launchd and setup a watch path. With a watch path, any time something changes in the folder you are watching, your code runs. The biggest difference between folder actions and the launchd action is that with the launchd action you don't know which files changed. You just know something changed. So your code has to figure out what the change actually was, but that shouldn't be too difficult in your case because if you're looking for an updated file you just check the modification date of the files.

You can google for launchd and watch paths if you want to try it.

Upvotes: 2

Chuck
Chuck

Reputation: 4892

Nope, doesn't exist directly. However, something similar could be accomplished with an idle handler that watches the files in the folder to see if their modification date has changed and perform an action on files where that's true.

Upvotes: 2

Related Questions