inotifywait alternative command for Mac?

Something like

$ macwatch dir_or_file cmd_to_execude_when_arg1_is_changed

during which I do not have to write XML. I am aware of https://stackoverflow.com/questions/1515730/is-there-a-command-like-watch-or-inotifywait-on-the-mac. It can be a wrapper to launchd - I just want to be able to enter the above command.


The StackOverflow question you've quoted has been added another answer - there's fswatch utility right there in Homebrew.

Please note fswatch command is more similar to inotifywatch, not inotifywait. Means, instead of one-shot waiting for file changes and then exiting, it enters an infinite loop printing the changed files - so you can catch the changes with an Unix pipe. Then your script would be "inside out" let's say.

For instance, on Linux I usually have a oneliner which runs my command on file changes using inotifywait:

while true; do inotifywait -q -e modify files... ; my_command; done

While for fswatch to have same effect I need to:

fswatch files... | (while read; do my_command; done)

The above assumes you don't need changed files as arguments to your command. If it happens you need them, it'd look like this:

fswatch files... | (while read x; do echo $x | xargs my_command; done)

Hope this helps :)

cheers