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.

For launchd there is WatchPaths (and for some more specific case QueueDirectories) which monitors changes on a path. However, if it is a directory, it will only recognize creations/deletions in the directory, i.e. not changed content of the containing files or any changes in any subdirectories (see here).

(For Linux, some good solutions seem to be listed here.)

It seems like launchd is not able to do it, is it?

I could write my own always-running daemon which extends launchd by this functionality, via FSEvents (or kqueue, fam or gamin?).

Or are there existing projects/tools which can do that?

share|improve this question

1 Answer 1

launchd should also monitor for changes to files (directly) under directories in WatchPaths.

Try saving this plist as ~/Library/LaunchAgents/test.plist:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>test</string>
  <key>ProgramArguments</key>
  <array>
    <string>say</string>
    <string>a</string>
  </array>
  <key>WatchPaths</key>
  <array>
    <string>~/Documents/</string>
  </array>
</dict>
</plist>

Then run launchctl load ~/Library/LaunchAgents/test.plist and modify some file under ~/Documents/. The program should be run even if you modify the file without performing an atomic save or even if the modification time of ~/Documents/ is not changed.

Note that launchd does not monitor for changes in subdirectories of the watched directories. Tilde expansion works in the arguments for WatchPaths by default, but there is no way to enable filename expansion. (EnableGlobbing only applies to ProgramArguments.)

share|improve this answer
    
According to my link, it does not. But even if it does, it is still not useful for me because I want a solution which monitors all of the content, i.e. also subdirectories. –  Albert Oct 9 '13 at 15:07

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.