Created
November 2, 2011 09:54
-
-
Save masui/1333288 to your computer and use it in GitHub Desktop.
Find the newest OmniGraffle document on Mac with Spotlight+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
# | |
# Find the newest OmniGraffle document | |
# | |
framework 'Cocoa' | |
def finish(notification) | |
if @query.resultCount > 0 then | |
puts @query.resultAtIndex(0).valueForAttribute('kMDItemPath') | |
end | |
exit | |
end | |
@query = NSMetadataQuery.alloc.init | |
@query.searchScopes = [ "#{ENV['HOME']}" ] | |
# @query.setSortDescriptors([NSSortDescriptor.alloc.initWithKey('kMDItemContentModificationDate', | |
ascending:false)]) | |
@query.sortDescriptors = [NSSortDescriptor.alloc.initWithKey('kMDItemContentModificationDate', | |
ascending:false)] | |
NSNotificationCenter.defaultCenter.addObserver(self, | |
selector:'finish:', | |
name:'NSMetadataQueryDidFinishGatheringNotification', | |
object:@query) | |
@query.predicate = NSPredicate.predicateWithFormat("kMDItemContentType == %@", | |
"com.omnigroup.omnigraffle.graffle") | |
@query.startQuery | |
NSRunLoop.currentRunLoop.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment