Created
February 4, 2012 23:50
-
-
Save segphault/1741191 to your computer and use it in GitHub Desktop.
Querying spotlight with MacRuby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def performSearch(pred, &cb) | |
search = NSMetadataQuery.alloc.init | |
search.predicate = pred | |
search.searchScopes = [File.expand_path("~")] | |
NSNotificationCenter.defaultCenter.addObserverForName( | |
"NSMetadataQueryDidFinishGatheringNotification", object:nil, queue:nil, | |
usingBlock: Proc.new {|n| n.object.results.each {|r| cb.call(r) } }) | |
search.startQuery | |
end | |
pred = NSPredicate.predicateWithFormat("kMDItemDisplayName like[c] '*whatever*'") | |
performSearch(pred) {|r| puts r.valueForAttribute("kMDItemDisplayName") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment