How to use inotify-tools linux shell methods for osx

To control the file on Linux, I can use inotify tools like this

#!/bin/bash # with inotify-tools installed, watch for modification of file passed as first param while inotifywait -e modify $1; do # do something here done 

but how to achieve this in OSX?

+6
source share
3 answers

If you want to associate this with a Python script, you can use Watchdog, which works with both Linux and OSX.

https://pypi.python.org/pypi/watchdog

Here's what it looks like to replace pyinotify with watchdog:

https://github.com/raphdg/baboon/commit/2c115da63dac16d0fbdc9b45067d0ab0960143ed

Watchdog also has a shell utility called watchmedo :

 watchmedo shell-command \ --patterns="*.py;*.txt" \ --recursive \ --command='echo "${watch_src_path}"' \ . 
+5
source

Yes, you can use the FSEvents API

+3
source

You can use the entr tool. Usage example:

 ls some_file | entr do_something 

On a Mac, install via Brew: brew install entr .

0
source

Source: https://habr.com/ru/post/894421/


All Articles