[MacRuby-devel] Trying to use spotlight programmatically

Martin Hawkins martin.hawkins at gmail.com
Mon Feb 7 10:25:45 PST 2011


This is really beyond the remit of this group, but I thought I'd try
here first as you guys are so helpful!

I'm trying to use spotlight programmatically.
I've downloaded the sample apps and used ideas from those - the code
works fine in MacRuby.

Where I'm coming unstuck is when I try to search mail. When creating
an ordinary spotlight search, you can add a criteria 'Spotlight items
are included'.
This is required when searching on something like Author Email
addresses (which translates to kMDItemAuthorEmailAddresses), because
without it, no hits are recorded. I mention
kMDItemAuthorEmailAddresses because as the attribute exists, the
expectation that a query can be parsed using it is set.
If you create two searches, one with and one without the spotlight
requirements line, save the searches and compare them (they are
in .plist format), the one with the 'Spotlight items are included'
criteria has the key FinderFilesOnly set to false:

<key>FinderFilesOnly</key>
		<false/>

and the following extra criteria in FXCriteriaSlices:
<dict>
  <key>criteria</key>
  <array>
    <string>com_apple_SearchSpotlightItemsAttribute</string>
    <integer>1230</integer>
  </array>
  <key>displayValues</key>
  <array>
    <string>SEARCH_SPOTLIGHT_ITEMS</string>
    <string>YES</string>
  </array>
  <key>rowType</key>
  <integer>0</integer>
  <key>subrows</key>
  <array/>
</dict>

I can't see documentation that explains how to achieve this
programmatically; my programmatic search, like the ordinary spotlight
search without the 'Spotlight items are included', yields 0 hits at
the moment.
Any help very welcome!


More information about the MacRuby-devel mailing list