2008年2月27日 星期三

Macworld | Cut through the Clutter


Macworld | Cut through the Clutter:


This is just a GREAT article. I was playing with Smart Folders tonight and noticed that you cannot do boolean criterion on searches. Most of the time, googling for Chinese data gives you only what you can find in Tiger's help file. But this article, digging deep into the RAW search of the spotlight function, let you control almost every aspect of the Smart Folder ability.


Technorati Tags: , ,




Spotlight 本身的查詢其實是可以加上 OR 條件的(預設的智慧型檔案夾的搜尋條件只能限制成 AND,也就是說,如果把列出兩種種類:PDF、JPEG當作條件的話,會什麼都找不到,因為沒有檔案同時又是PDF又是JPEG);例如:


(kMDItemKind == *JPEG*) || (kMDItemKind == *PDF*)


k是 constant (it's Hungarian notation, I suppose), MD=metadata, ItemKind 就是該項目的類型(很拗口但是這翻成英文就很順了),寫起來就是類似程式語言的 boolean expression。


Smart Folder Info 其實每個智慧型檔案夾建立以後,背後都會有一大串像上面的那種 spotlight 原始查詢條件句。比如我剛剛建了一個新的智慧型檔案夾,是把自己最近兩週內動到的工作文件找出來方便繼續修改,做好了以後,去智慧型檔案夾的上層,選這個智慧型檔案夾的『簡介』,在“問題“的地方就可以看到一大串文字。我的這個智慧型檔案夾的 query 是:


(kMDItemFSContentChangeDate >= $time.today(-14)) && (kMDItemContentType != com.apple.mail.emlx) && (kMDItemContentType != public.vcard)


也就是說,兩週內修改的任意檔案(kMDItemFSContentChangeDate >= $time.today(-14))、而且(&&)不是 Apple Mail 郵件 (kMDItemContentType != com.apple.mail.emlx) 而且 (&&) 不是名片檔 (kMDItemContentType != public.vcard) 的都會自動放在這個檔案夾裡面 (但是我選取的來源檔案夾不包括在這個條件裡面)。


如果這些條件都沒辦法精確找到你要的檔案的話,也可以幫個別檔案加上 spotlight comment,這樣就可以用 comment 裡面的關鍵次來一把抓,威力真的是相當強大啊!!


這邊有 Apple 官方的完整 Spotlight Metadata 的解說


沒有留言:

張貼留言