Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I want to use launchd to kick off a script to backup changed files. It looks like it should work for what I want to do, but I don't know how to pass to my script that launchd starts, the path of the updated file. So if I'm watching directory foo and file bar.txt is changed, how do I get my launchd.plist or the script it runs to get the value of bar.txt?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

I haven't found any way to do it with launchd. Could you just use rsync or something? Or check the modification dates in the script, by for example using find if it's a shell script:

find /some/path -mindepth 1 -maxdepth 1 -mtime -20s

Folder actions do get pathnames as an argument, but they are only run when files are added to a folder and not when files are modified. You can create a folder action by using the folder action template in Automator, or by saving a script like the one below in ~/Library/Workflows/Applications/Folder Actions/ and then enabling the script from Folder Actions Setup.

on adding folder items to this_folder after receiving these_items
    say POSIX path of item 1 of these_items
end
share|improve this answer

Your Answer

 
discard

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.