Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using Spotlight to watch for file change



I'd like to watch one or more specific files to see if an external program has modified them.

Three methods immediately pop to my mind:
    kqueue (which I know almost nothing about),
    Spotlight (which seems like it ought to be the right answer)
    polling the file mod date (which I'd like to avoid)

There doesn't appear to be a simple way to register for NSNotifications when a file is changed, so the best I can see is to make a live Query of the form: kMDItemPath == myFileNameOfInterest and file's mod date > now. Is this the right approach?

Also, does anyone have any experience with the scalability of multiple queries? For example, if I have 20 files I want to watch, would I be better off keeping 20 queries live or one really complicated query? 100 files? Truly obscene numbers of files (thousands) are not likely to occur for my expected usage, so perhaps it doesn't matter overly much...

Have any readers of the list used this type of Spotlight query for this type of thing? Has a user's privacy settings (don't index this area) been a problem? I don't think there's a way to detect if the file path I specify is fated to never trigger a notification because of privacy settings (so I could fall back to another solution)... Bummer.

Before I spend a day or two writing sample code to try the approaches, I was hoping someone might offer opinions based on similar experiences... Thanks!

-- Tim Gogolin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.