[Pyobjc-dev] NSMetadataQuery - Spotlight Query problems
Brought to you by:
ronaldoussoren
|
From: Chris S. <cj...@uo...> - 2008-09-07 07:05:42
|
Hi All, i'm fairly new at PyObjC, so bear with me. I'm trying to search the local FS for files using an MSMetadataQuery object. I've been looking at the PredicateEditorSample here on pyobjc.sourceforge.net, which I have based alot (read: all :) ) of my code from. Heres some code from the class: class SystemBridge(NSObject): #deleted some stuff query = objc.ivar() #deleted some more stuff def newQuery_(self, _filename, _filetype): self.query = NSMetadataQuery.alloc().init() #Create a notification so we can see what is happening with the search nf = NSNotificationCenter.defaultCenter() nf.addObserver_selector_name_object_(self, 'queryNotification:', None, self.query) #Create the query self.query.setSortDescriptors_([NSSortDescriptor.alloc().initWithKey_ascending_('kMDItemDisplayName', True)]) self.query.setDelegate_(self) #########Set the predicate, having problems here? #thePredicate = NSPredicate.predicateWithFormat_("(kMDItemDisplayName LIKE[cd] 'preso*') && (kMDItemContentType LIKE[cd] 'com.apple.iwork.keynote.key')") thePredicate = NSPredicate.predicateWithFormat_("(kMDItemDisplayName = '*')") keynotePredicate = NSPredicate.predicateWithFormat_("(kMDItemContentType = 'com.apple.iwork.keynote.key')") #Try a compound out instead of one just one of the above... don't need to do this but I was experimenting predicate = NSCompoundPredicate.andPredicateWithSubpredicates_([keynotePredicate, thePredicate]) #Start the search self.query.setPredicate_(predicate) self.query.startQuery() return def queryNotification_(self, note): #Find the query status by looking at the note if note.name() == NSMetadataQueryDidStartGatheringNotification: print "Starting Search" elif note.name() == NSMetadataQueryDidFinishGatheringNotification: print "Search Finished" getQueryResults_(note) elif note.name() == NSMetadataQueryGatheringProgressNotification: print "Searching..." elif note.name() == NSMetadataQueryDidUpdateNotification: print "Found something" def getQueryResults_(self, notif): results = notif.object().results() NSLog("Search count = %d", len(results)) The weird thing is, i get zero search results. I can use the predicate from this in another application (the Fortunes app example) and it searches just fine, so i'm not so sure if it is my predicates causing the problem. Ouput: Starting Search And thats it. I'm expecting a count of the results, there are several files that start with 'preso' that are keynote files, but no luck. Any ideas would be appreciated! Thanks. |