Hello ,
The code posted by Kaelin works great for me,
After counting the number of search results now I would like to know the path of files found but to do this I have big difficulty
I'm trying to figure out how to make it works the MDQueryGetAttributeValueOfResultAtIndex or MDItemCopyAttribute to read out the KMDItemPath or KMDItemFSName but I was a bit confused by the "Pointer" returned and even I get a # Illegal instruction as you can see in the following code:
framework "CoreServices"
#=> true
query = MDQueryCreate(KCFAllocatorDefault, "kMDItemDisplayName = '*.pdf'", [KMDItemFSName,KMDItemPath] , nil)
#=> #<__NSCFType:0x2005d63a0>
MDQueryExecute(query, KMDQuerySynchronous)
#=> true
# item = MDQueryGetResultAtIndex(query, 1);
#=> #<Pointer:0x20052dc80>
count = MDQueryGetResultCount(query)
p "found #{count} documents" #=> 981
a = MDQueryGetAttributeValueOfResultAtIndex(query, KMDItemFSName, 2)
p a #<Pointer:0x20059aee0> ..not a NSString
p a[0] #0
p a[1] #4
item_ref = MDQueryGetResultAtIndex(query, 1)
p item_ref #<Pointer:0x200582460>
p item_ref.class #Pointer ..not a MDItemRef
path = MDItemCopyAttribute( item_ref, KMDItemPath) #Illegal instruction
p path
I've found an older post of 2009 titled: "[MacRuby-devel] spotlight - MDItemRef" where Laurent said: "I'm afraid the MD* APIs haven't been covered by BridgeSupport yet.."
but because of i can see the MDQueryGetResultCount working I hope that there is a way to enumerate the results of the query to get the attributes ( path especially )
I would be very happy if anyone has any idea,
Thanks
Franco