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 





> Kaelin Colclausure
> 
Kaelin Colclasure kaelin at apple.com 
Tue Feb 8 11:49:39 PST 2011

Previous message: [MacRuby-devel] Trying to use spotlight programmatically
Next message: [MacRuby-devel] BridgeSupport Requirement
Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Martin,
        
The FinderFilesOnly stuff is not really relevant to other applications using 
Spotlight. You should not need to do anything special to find email results. 
Try, for example, using the mdfind command from Terminal:

$ mdfind -literal 'kMDItemAuthorEmailAddresses == *'

If your query is not returning any results, there is probably something else 
going on. Here is a quick example using macirb:
---8<---
[kaelin at melete trunk]$ macirb
irb(main):001:0> framework 'CoreServices'
=> true
irb(main):002:0> query = MDQueryCreate(KCFAllocatorDefault, 
"kMDItemAuthorEmailAddresses == *", nil, nil)
=> #<__NSCFType:0x4001149e0>
irb(main):003:0> MDQueryExecute(query, KMDQuerySynchronous)
=> true
irb(main):004:0> MDQueryGetResultCount(query)
=> 66883
irb(main):005:0> 
--->8---

_______________________________________________
MacRuby-devel mailing list
MacRuby-devel@lists.macosforge.org
http://lists.macosforge.org/mailman/listinfo.cgi/macruby-devel

Reply via email to