macosshmonitorinotifywaitfswatch

How to watch file changes on Mac OSX using FSWatch?


I'm trying to use fswatch to translate the following lines from a linux bash script to be able to run it on Mac OSX:

inotifywait -r -m 'myfolder/' | while read MODFILE
do
    echo "something"
done

Since inotifywait doesn't work on Mac OSX I want to substitute the first line for FSWatch. Although the README refers to the fswatch man page, it doesn't provide a link to it and a search around the internet doesn't get me anything. So I tried messing around a bit.

I created a folder called testfswatch/ and I tried running the following commands in the parent folder and then adding and changing files on the testfswatch/ folder:

fswatch -o testfswatch/ | echo "LALA"
fswatch -o testfswatch/ | someSimpleProgram
fswatch -o testfswatch/ | xargs -n1 -I{} echo "LALA"
fswatch -o testfswatch/ | xargs -n1 -I{} ./someExecutable
fswatch -o testfswatch/ | xargs -n1 echo "LALA"
fswatch -o testfswatch/ | xargs -n1 someExecutable
// And more variations of the above

None of these commands seem to do anything when I change or add files in the tesfswatch/ folder though.

Does anybody know what I'm doing wrong here? All tips are welcome!


Solution

  • pre-1.0 versions of fswatch use a slightly different invocation syntax, compared to 1.0 and later. Make sure that you're running a version later than 1.0, You may want to upgrade if your version is older than that.