4

In Windows, I can use the FindNextChangeNotification API to watch a file or folder for changes. For example, I can watch a folder and get notified when a file is added or removed.

Is there a similar API on OS X?

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
Gregory Higley
  • 15,923
  • 9
  • 67
  • 96
  • It occurs to me that I could do this with Spotlight, but I'm looking for a more low-level solution. – Gregory Higley Sep 18 '09 at 03:06
  • also check out [fswatch from this question](http://stackoverflow.com/questions/1515730/is-there-a-command-like-watch-or-inotifywait-on-the-mac/13807906#13807906) – cwd Jun 06 '13 at 13:04

2 Answers2

9

Mac OS X v10.5 introduces the File System Events API. Have a look at:

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
3

FSEvents is nice, but for watching just a small set of files or folders it's rather overkill, and it does require Leopard or newer. (The underlying technology was introduced in Tiger, but the API wasn't public.)

As a possible alternative, note that OS X inherits kqueue from FreeBSD (at least as of Panther). You can search for examples of EVFILT_VNODE usage, that's what you want to use to watch for file alterations.

ephemient
  • 198,619
  • 38
  • 280
  • 391