通过PyObjC查询一系列日期的Spotlight

时间:2012-03-24 15:16:54

标签: python pyobjc spotlight

我通过pyobjc使用聚光灯。除了当我尝试使用kMDItemContentCreationDate限制时间段时,哪个工作正常。我认为问题在于我的时间格式。任何帮助将不胜感激。

    from Cocoa import *
    import sys

    emails = [sys.argv[1], ]
    predicate = "(kMDItemContentType = 'com.apple.mail.emlx') && (" + \
             '||'.join(["((kMDItemAuthorEmailAddresses = '%s'))" % m for m in emails]) + \
              "&& (kMDItemContentCreationDate > '2011-03-23 00:00:00')" + \
              "&& (kMDItemContentCreationDate < '2012-03-24 00:00:00')" + \
              ")"

    query = NSMetadataQuery.alloc().init()
    query.setPredicate_(NSPredicate.predicateWithFormat_(predicate))
    query.setSortDescriptors_(NSArray.arrayWithObject_(NSSortDescriptor.alloc().initWithKey_ascending_('kMDItemContentCreationDate', False)))
    query.startQuery()
    NSRunLoop.currentRunLoop().runUntilDate_(NSDate.dateWithTimeIntervalSinceNow_(5))
    query.stopQuery()
    results = query.results()[:5]

    for item in results:
        print "subject: ", item.valueForAttribute_("kMDItemSubject")

0 个答案:

没有答案