I want to watch multiple folders with fswatch on Mac

I see in the documents for fswatch it has $ fswatch -0 [opts] [paths] | xargs -0 -n 1 -I {} [command] but I don't really understand how I'm supposed to add multiple paths to that - I'm watching two paths lib and test. I've tried: fswatch -r lib,test, fswatch -r lib test, and finally fswatch -r [lib test] How do I watch multiple paths with fswatch at the same time?

Answers

fswatch path/one path/two echo "whatever" (separate the paths using ' ' space)

Posted on by mikhuang

The only possibility I found is to execute the fswatch command multiple times:

do_backup() {
    // what you want to do
    rsync -ahhvzPR --delete $FILE $BACKUP_DIR
}

fswatch -r lib | while read FILE; do
    do_backup
done &

fswatch -r test | while read FILE; do
    do_backup
done &

This will start the process for both directories in detached mode.

More about the detached mode can be found here.

Posted on by KittMedia

Relevant tags