Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 It can be a wrapper to launchd - I just want to be able to enter the above command.

share|improve this question
I added a new answer on that question you linked to -… – cwd Dec 10 '12 at 19:38

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 inotifiwait. 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 :)


share|improve this answer
Actually I need such things so often by myself, that after answering this I wrote such a wrapper: – Wojciech Kaczmarek Aug 24 '14 at 17:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .