0

As the title states i need to watch a directory for changes(mainly for file additions) using python

I stumble upon a few solutions here but none of them work properly

1.One solution was using "fcntl", I tried it on my system but it failed with an error "no attribute F_SETSIG".Googling it resulted in nothing useful

2.Python module Watchdog fails to install as i don't have xcode, which i don't want to download(too big to download and lots of unnecessary things for such small work)

The accepted solution was windows specific and none of others work on osx without big packages

So in the end I don't want any solutions involving XCODE, PyQT, polling, busy loop(i.e. checking DIR every few seconds)

Applescripts support this by default, so I think python should too without any big modules/packages

I am using OS X 10.7.2 and python 2.7.3 by the way

Thanks in advance

Community
  • 1
  • 1
rockstarjindal
  • 293
  • 1
  • 5
  • 15

2 Answers2

1

The API you want to be using is the FSEvents API. Python doesn't ship with bindings to that API, so you'll need to either make your own bindings or use a library such as MacFSEvents or python-watchdog. However you really should just install Xcode -- these libraries require compiling the C bindings, and Xcode is the easiest way to get a C compiler.

If you really want to avoid Xcode, you could roll your own bindings using the ctypes module, but that's going to be a big pain in the neck.

Applescripts support this by default, so I think python should too without any big modules/packages

Tough luck. The various 3rd-party libraries which are available are not that big, they just need a C compiler to work.

Adam Rosenfield
  • 390,455
  • 97
  • 512
  • 589
  • I do have a installation of C compiler whose dmg is built from XCODE itself.Looks like it isn't that compatible.Thanks anyway.... – rockstarjindal Jul 19 '12 at 22:22
0

I use watchdog right now on osx. It works great. Install xcode. Or just the command line tools for the compilers.

You can install the gcc compiler without xcode: https://github.com/kennethreitz/osx-gcc-installer

If you really want an applescript approach you can use the python bindings appscript: http://appscript.sourceforge.net/py-appscript/index.html
I use those too and they work great.

So in the end I don't want any solutions involving XCODE, PyQT, polling, busy loop(i.e. checking DIR every few seconds)

Basically you are saying you dont want anything at all. Any solution is going to use a form of polling. Whether its system triggered or app busy loop. You just need to take a second to install the compilers to use the solution of your choice.

jdi
  • 90,542
  • 19
  • 167
  • 203
  • Already installed that compiler without xcode.But watchdog installation fails in the end without giving any dependency warnings – rockstarjindal Jul 19 '12 at 22:27
  • 1
    re: "Any solution is going to use a form of polling" Not necessarily. Efficient implementations use filesystem events (hence the name fsevents) which actually involve the kernel emitting signals when it performs an action on a watched directory. This avoids polling. The problem is how to hook into these events. – SpliFF Sep 20 '18 at 06:41
  • @SpliFF I think I used the term "polling" too loosely... 6+ years ago :) – jdi Sep 20 '18 at 08:14