I have an app that displays some text from an external text file that is created by Filemaker, and if Filemaker updates the file I need to stay in sync. Right now I have a timer hammering away at the text file to see if it has been updated, but I’m sure there is a better way. I have the path to the file, how would I set up a notification to check if the file has been modified since I last read it so I can read it again? Thanks so much.
Hi,
this could be accomplished with file system events (FSEvents) or kqueue,
but this requires C or Objective-C code to perform the callbacks
Further to Stefan’s answer, Objective-C classes wrapping FSEvents and kqueue are available: here’s a good pointer:
stackoverflow.com/questions/1386743/observe-a-file-or-folder-in-objective-c
Thanks Stefan and Shane,
Ok, so if I wanted to implement the code at the link below, how would I do it through Applescript Obj-C? I’ve imported the .m and .h files in to my project, but I’m really bad at figuring out how to use the Obj-C code. I’m sure others would find this useful so if someone could walk us through it it would be MUCH appreciated. Thanks.
Probably like this:
set theQueue to current application's UKKQueue's sharedFileWatcher()
theQueue's setDelegate_(me)
theQueue's setAlwaysNotify_(false)
theQueue's addPath_("/path/to/watch")
on watcher_receivedNotification_forPath_(watcher, notif, thePath)
-- do your stuff
end watcher_receivedNotification_forPath_
You could also use addPathToQueue_notifyingAbout_ instead of add Path_ to reduce the number of times the handler is called.