Sunday, November 29, 2020

#1 2012-01-16 01:16:02 am

evandau,
Member
Registered: 2006-10-09
Posts: 78

Notification for external text file changed

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.

Offline

 

#2 2012-01-16 04:48:02 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11699
Website

Re: Notification for external text file changed

Hi,

this could be accomplished with file system events (FSEvents) or kqueue,
but this requires C or Objective-C code to perform the callbacks


regards

Stefan

Offline

 

#3 2012-01-16 05:05:25 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6499

Re: Notification for external text file changed

Further to Stefan's answer, Objective-C classes wrapping FSEvents and kqueue are available: here's a good pointer:

stackoverflow.com/questions/1386743/obs … bjective-c


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#4 2012-01-16 12:48:32 pm

evandau,
Member
Registered: 2006-10-09
Posts: 78

Re: Notification for external text file changed

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. 

http://zathras.de/angelweb/sourcecode.htm#UKKQueue

Offline

 

#5 2012-01-16 04:37:27 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6499

Re: Notification for external text file changed

Probably like this:

Applescript:

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)