SpotlightQuery.Query

From Xojo Documentation

Property (As String )


aSpotlightQuery.Query = newStringValue
or
StringValue = aSpotlightQuery.Query

Supported for all project types and targets.

The query string that will be passed to the Spotlight engine.

Notes

You search on the metadata attribute keys provided by Apple using their format. See the notes for the format of the query.

Example

The following asynchronous query uses the search string that the user enters into a TextField and displays the filename and its absolute path in a Listbox. It uses a SpotlightQuery control named "Query" that has been added to the window.

First, add the following method "UpdateList" to the window:

Sub UpdateList()
ListBox1.RemoveAllRows
Query.Pause
For i As Integer = 0 To Query.Count - 1
ListBox1.AddRow(Query.Item(i).File.DisplayName)
ListBox1.CellValueAt(ListBox1.LastAddedRowIndex, 1) = Query.Item(i).File.NativePath
Next
Query.Resume
End Sub

In the SpotLightQuery's Changed and Completed event handlers, call the UpdateList method.

In a PushButton, enter the following code in its Action event handler.

If TextField1.Value <> "" Then
Query.Query = "kMDItemDisplayName == ""*" + TextField1.Value + "*"""
Query.Run
Else
MessageBox("Please enter a file name to search for.")
End If

Exception e As SpotlightException
MessageBox("A Spotlight error occurred.")