4

Can I use the Spotlight APIs (they exist, right?) in Cocoa to determine if Spotlight (in the upper-right corner) would match a given filePath with a given string?

In other words, given a filePath such as "/Users/enchilada/Desktop/MapOfUSA.pdf", and a string such as "Virginia", how would I tell if Spotlight would show this file when "Virginia" would have been typed in the upper-right Spotlight search? (As you can imagine, in the example shown, it would probably be matched, because a PDF map of the USA probably contains Virgina.)

If possible, a simple code piece to do this would be appreciated.

Enchilada
  • 3,859
  • 1
  • 36
  • 69
  • 2
    The first sentence of your question can be answered with a quick Google search ("cocoa spotlight api"). The results of that search will lead you to the rest. – Joshua Nozzi Sep 15 '10 at 15:17
  • 2
    Actually, leaving out 'api' gives much better results when looking for Cocoa Spotlight documentation? Furthermore, the @Enchilada seems to labor under the idea that said 'api' will give access to the Finder GUI -- it would have been nice to clear up that misunderstanding instead of downvoting an obvious newbie question. I'm reversing the downvote. – Elise van Looij Jun 06 '11 at 12:42

1 Answers1

6

You can use the NSMetadataQuery class or its underlying CFType MDQuery. O'Reilly has published an example.

zneak
  • 134,922
  • 42
  • 253
  • 328