Platforms to show: All Mac Windows Linux Cross-Platform

NSMetadataQueryMBS class

Type Topic Plugin Version macOS Windows Linux iOS Targets
class iCloud MBS MacCloud Plugin 11.3 ✅ Yes ❌ No ❌ No ✅ Yes All
The NSMetadataQuery class encapsulates the functionality provided by the MDQuery opaque type for querying the Spotlight metadata.
Example
// find all PDF files in the home folder with Spotlight
// MyMetadataQuery is a subclass of NSMetadataQueryMBS with the DidFinishGathering event implemented.
// Query is a property of the window: Query As MyMetadataQuery
Query = New MyMetadataQuery
Query.predicate = NSPredicateMBS.predicateWithFormat("kMDItemContentType == 'com.adobe.pdf'")

Var scopes() As String = Array(NSMetadataQueryMBS.NSMetadataQueryUserHomeScope)
Query.setSearchScopes scopes

If Not Query.startQuery Then
MessageBox "Failed to start query."
End If

// in MyMetadataQuery:
Sub DidFinishGathering(n As NSNotificationMBS) Handles DidFinishGathering
Me.stopQuery
For Each item As NSMetadataItemMBS In Me.results
System.DebugLog item.Path
Next
System.DebugLog Me.resultCount.ToString + " PDF files found."
End Sub

You may prefer MDQueryMBS class from our plugins. NSMetadataQueryMBS exists as it supports iCloud search.

NSMetadataQuery objects provide metadata query results in several ways:

  • As individual attribute values for requested attributes.
  • As value lists that contain the distinct values for given attributes in the query results.
  • A result array proxy, containing all the query results. This is suitable for use with Cocoa bindings.
  • As a hierarchical collection of results, grouping together items with the same values for specified grouping attributes. This is also suitable for use with Cocoa bindings.
Queries have two phases: the initial gathering phase that collects all currently matching results and a second live-update phase.
By default the receiver has no limitation on its search scope. Use setSearchScopes to customize.
By default, notification of updated results occurs at 1.0 seconds. Use setNotificationBatchingInterval to customize.
You must set a predicate with the setPredicate method before starting a query.

This class has no subclasses.

Blog Entries

Some examples using this class:

Some related classes:


The items on this page are in the following plugins: MBS MacCloud Plugin.


NSMetadataItemMBS   -   NSMetadataQueryResultGroupMBS


The biggest plugin in space...