First I want to thank all people above who gave me valuable clues. Now I answer my own question after I got it working. Here some sample code (macoslib is needed):
I have a Window property
pRunningQuery As NSMetadataQuery = nil
and I call the Spotlight search by using:
[code] //NSPredicate
declare function predicateWithFormat lib “Cocoa” selector “predicateWithFormat:argumentArray:” (class_id as ptr, FormatStr as CFStringRef, argumentArray as Ptr) as Ptr
//
dim volF as FolderItem = PopVolumelist.RowTag(PopVolumelist.ListIndex)
dim searchLocation as String = volF.NativePath
dim searchAttribute as String = popAttributeList.Text
dim searchCompareType as String = popAttributeCompareType.RowTag(popAttributeCompareType.ListIndex)
dim searchString as String = tfSearchString.Text
logLine(“Search location = " + searchLocation)
logLine(“Looking for " + searchAttribute + " " + searchCompareType + " “”” +searchString + “””")
pRunningQuery = new NSMetadataQuery
if pRunningQuery = nil then
logLine(“NSMetadataQueryRef is nil”)
return
end
dim searchLocationsArray As NSMutableArray = NSMutableArray.CreateWithObject(new NSURL(volF))
pRunningQuery.setSearchScopes(searchLocationsArray)
dim searchQuery As CFStringRef = searchAttribute + " " + searchCompareType + " “”" + searchString + “”""
logLine("searchQuery: "+ searchQuery)
pRunningQuery.setPredicate(predicateWithFormat(Cocoa.NSClassFromString(“NSPredicate”), searchQuery, nil))
if pRunningQuery.startQuery then
logLine(“startQuery was successful”)
else
logLine(“startQuery failed”)
end
logLine(“result check timer started”)
tiSearchWatcher.Mode = Timer.ModeMultiple
[/code]
Note the Timer at the end of the method where I check if the query is running using this code in timer.action:
[code] if pRunningQuery = nil then
logLine(CurrentMethodName + “: pRunningQuery is nil!”)
me.mode = 0
return
end
if not pRunningQuery.isRunning then
logLine(CurrentMethodName + “: isRunning false”)
me.mode = 0
fetchSearchResults()
return
end
//logLine(“Timer: isRunning true”)
if pRunningQuery.isStopped then
logLine(CurrentMethodName + “: isStopped”)
me.mode = 0
return
end
dim resCount As integer = pRunningQuery.resultCount
logLine(CurrentMethodName + “: got " + str(resCount) + " results”)
[/code]
When the search has finished I get the results via
[code]Sub fetchSearchResults()
if pRunningQuery = nil then
logLine(CurrentMethodName + “: pRunningQuery is nil!”)
return
end
dim resCount As integer = pRunningQuery.resultCount - 1 // 0 based
logLine(CurrentMethodName + “: got " + str(resCount) + " items”)
for i as integer = 0 to resCount
dim aResult As CFStringRef = pRunningQuery.resultAtIndex(i)
logLine(CurrentMethodName + “: result(”+str(i)+"= " + aResult)
next
End Sub
[/code]
And here is finally the NSMetadataQuery class with all used declares:
[code]#tag Class
Protected Class NSMetadataQuery
Inherits Cocoa.NSObject
#tag Method, Flags = &h1000
Sub Constructor()
// Calling the overridden superclass constructor.
// Note that this may need modifications if there are multiple constructor choices.
// Possible constructor calls:
// Constructor() – From NSObject
// Constructor(obj_id as Ptr, hasOwnership as Boolean = False) – From NSObject
super.Constructor(Allocate(“NSMetadataQuery”))
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Function isRunning() As Boolean
declare function isGathering lib "Cocoa" selector "isGathering" (class_id as ptr) as Boolean
return isGathering(self)
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function isStarted() As Boolean
declare function isStarted lib "Cocoa" selector "isStarted" (class_id as ptr) as Boolean
return isStarted(self)
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function isStopped() As Boolean
declare function isStopped lib "Cocoa" selector "isStopped" (class_id as ptr) as Boolean
return isStopped(self)
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function resultAtIndex(index as integer) As String
declare function resultAtIndex lib "Cocoa" selector "resultAtIndex:" (class_id as ptr, index as integer) as Ptr
// NSMetadataItem
declare function valueForAttribute lib "Cocoa" selector "valueForAttribute:" (class_id as ptr, attrName as CFStringRef) as CFStringRef
dim anItem As Ptr = resultAtIndex(self, index) // result is NSMetadataItem
dim anItemPath As string = valueForAttribute(anItem, "kMDItemPath")
return anItemPath
End Function
#tag EndMethod
#tag Method, Flags = &h0
Function resultCount() As Integer
declare function resultCount lib "Cocoa" selector "resultCount" (class_id as ptr) as Integer
return resultCount(self)
End Function
#tag EndMethod
#tag Method, Flags = &h0
Sub setPredicate(predicate as Ptr)
declare sub setPredicate lib "Cocoa" selector "setPredicate:" (class_id as ptr, predicate as Ptr)
setPredicate(self, predicate)
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Sub setSearchScopes(searchLocationsArray as NSArray)
declare sub setSearchScopes lib "Cocoa" selector "setSearchScopes:" (ref as ptr, SearchArray as Ptr)
setSearchScopes(self, searchLocationsArray)
End Sub
#tag EndMethod
#tag Method, Flags = &h0
Function startQuery() As Boolean
declare function startQuery lib "Cocoa" selector "startQuery" (class_id as ptr) as Boolean
return startQuery(self)
End Function
#tag EndMethod
#tag Method, Flags = &h0
Sub stopQuery()
declare sub stopQuery lib "Cocoa" selector "stopQuery" (class_id as ptr)
stopQuery(self)
End Sub
#tag EndMethod
#tag ViewBehavior
#tag ViewProperty
Name="Index"
Visible=true
Group="ID"
InitialValue="-2147483648"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="Left"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
#tag EndViewProperty
#tag ViewProperty
Name="Name"
Visible=true
Group="ID"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="Super"
Visible=true
Group="ID"
Type="String"
#tag EndViewProperty
#tag ViewProperty
Name="Top"
Visible=true
Group="Position"
InitialValue="0"
Type="Integer"
#tag EndViewProperty
#tag EndViewBehavior
End Class
#tag EndClass
[/code]