Tom
Tom

Reputation: 11

Not quite understanding NSMetadataQuery

I am looking for a class to use from the Cocoa API to perform a Spotlight search on the entire system. I looked at NSMetadataQuery and believe this is the class for this, however I don't understanding how to do this; primarily NSPredicate. I would like to search the system for a file named "test123.html" for example and get its full path. Examples are greatly appreciated. My code:

NSMetadataQuery *q = [[NSMetadataQuery alloc] init];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"kMDItemSFName == %@", @"test123456.png"];  
[q setPredicate:predicate];

[q startQuery];
while ([q isGathering]) {
    NSLog(@"%lu", [q resultCount]);
}

[q stopQuery];

This returns 0 results. Why?

Upvotes: 0

Views: 1579

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243156

kMDItemSFName should be kMDItemFSName

Upvotes: 3

Related Questions