Created
November 3, 2011 02:30
-
-
Save masui/1335617 to your computer and use it in GitHub Desktop.
Find large Microsoft Word documents on Mac with Spotlight+MacRuby
This file contains hidden or 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
# | |
# List large Microsoft Word files upto 10 | |
# | |
framework 'Cocoa' | |
def finish(notification) | |
max = @query.resultCount | |
max = 10 if max > 10 | |
(0...max).each { |i| | |
path = @query.resultAtIndex(i).valueForAttribute('kMDItemPath') | |
puts path | |
puts File.size(path) | |
} | |
exit | |
end | |
@query = NSMetadataQuery.alloc.init | |
@query.searchScopes = [ "#{ENV['HOME']}" ] | |
@query.sortDescriptors = [NSSortDescriptor.alloc.initWithKey('kMDItemFSSize',ascending:false)] | |
NSNotificationCenter.defaultCenter.addObserver(self, | |
selector:'finish:', | |
name:'NSMetadataQueryDidFinishGatheringNotification', | |
object:@query) | |
pred1 = NSPredicate.predicateWithFormat("kMDItemContentType == %@", "com.microsoft.word.doc") | |
pred2 = NSPredicate.predicateWithFormat("kMDItemContentType == %@", "org.openxmlformats.wordprocessingml.document") | |
preds = [pred1, pred2] | |
@query.predicate = NSCompoundPredicate.orPredicateWithSubpredicates(preds) | |
@query.startQuery | |
NSRunLoop.currentRunLoop.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment