How to view the file change directory

I am on a mac. I am using the Launchd WatchPaths directive to view the file change directory. My script runs only when adding or removing a file from the watched directory.

However, the script does not run when the file changes.

Essentially, I'm trying to create a DIY Dropbox to sync My Sites.

Is there a way to do this via launchd, bash or python?

I think linux has something like inotify, but I don't know about a solution for mac.

+3
source share
1 answer

I tried to use this problem using the MacFSEvents package ( available in PyPI ):

import os

from fsevents import Observer, Stream


def callback(file_event):
    print file_event.name # the path of the modified file


def main():
    observer = Observer()
    observe_path = os.getcwd() # just for this example
    stream = Stream(callback, observe_path, file_events=True)
    observer.start()
    observer.schedule(stream)


if __name__ == '__main__':
    main()

callback , , ( , , file_event.mask).

, , , ( , KeyboardInterrupt). API MacFSEvents README. , !

+2

All Articles