2011-08-05 41 views
6

linux的inotify工具外殼的方法來監測在linux下一個文件,我可以使用inotify工具類似這樣的如何實現在OSX

#!/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 

,但我怎麼會在OSX實現這一目標?

回答

3

是的,你可以使用FSEvents API

+0

這可以在shell腳本中使用嗎? –

+1

不,但是有一個python的包裝庫:http://pypi.python.org/pypi/MacFSEvents/0.2.4 – Baversjo

0

您可以使用entr工具。用法示例:

ls some_file | entr do_something 

在Mac上通過釀造安裝:brew install entr