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.

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 http://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.

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

1 Answer 1

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

cheers

share|improve this answer
    
Actually I need such things so often by myself, that after answering this I wrote such a wrapper: github.com/herenowcoder/forever/blob/master/forever –  Wojciech Kaczmarek Aug 24 at 17:13

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.