5

I'm implementing a free space on disk bar where while files are being copied, the free space bar updates. I need some way of being notified of file system changes. What's the best way to go about doing this?

indragie
  • 17,634
  • 15
  • 89
  • 161

2 Answers2

6

The File System Events Programming Guide has all the info you need. You want to register with the File System Events API (OS X 10.5 and later).

Barry Wark
  • 105,416
  • 24
  • 177
  • 204
  • Stu Connolly has a great Objective-C wrapper for the FSEvents C API called SCEvents. You can get it here: http://stuconnolly.com/blog/scevents-011/ – Rob Keniger Oct 01 '09 at 03:37
  • The above links are dead, so here we go: https://developer.apple.com/library/archive/documentation/Darwin/Conceptual/FSEvents_ProgGuide/UsingtheFSEventsFramework/UsingtheFSEventsFramework.html – StefanS Mar 06 '20 at 07:38
2

To monitor operations on individual files you can use kqueue file change notifications. Uli Kusterer has a nice Obj-C wrapper called UKKQueue.

You can get it here: http://zathras.de/angelweb/sourcecode.htm

If you want to watch an entire folder, FSEvents (and the SCEvents wrapper) will probably be of more use.

Nick Forge
  • 20,944
  • 7
  • 50
  • 77