Skip to content

Instantly share code, notes, and snippets.

@masui
Created November 2, 2011 09:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save masui/1333288 to your computer and use it in GitHub Desktop.
Save masui/1333288 to your computer and use it in GitHub Desktop.
Find the newest OmniGraffle document on Mac with Spotlight+MacRuby
#
# 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