有没有办法按类别在Mac 2011中搜索Outlook 2011中的联系人?
tell application "Microsoft Outlook"
-- get the category by name
set theCategory to item 1 of (every category whose name = "Recruiter")
-- correctly displays 'Recruiter [25]'
display dialog (name of theCategory) & " [" & (id of theCategory) & "]"
-- perform the search (incorrectly, it seems)
set theContacts to (every contact whose (every category contains theCategory))
-- should display ~100; actually displays 0
display dialog (count of theContacts)
end tell
答案 0 :(得分:1)
我认为OL字典实现中可能存在一些关于类别的错误/功能 - 我认为您的搜索语句应该有效,但我同意不
对此的一种解决方法是进行聚光灯搜索。这甚至可能是优选的,因为它可能比使用OL字典更快。简而言之,请使用以下内容替换set theContacts to ...
行:
set currentIdentityFolder to quoted form of POSIX path of (current identity folder as string)
set theContactIDs to words of (do shell script "mdfind -onlyin " & currentIdentityFolder & " 'kMDItemContentType == com.microsoft.outlook14.contact && com_microsoft_outlook_categories == " & id of theCategory & "' | xargs -I % mdls -name com_microsoft_outlook_recordID '%' | cut -d'=' -f2 | sort -u | paste -s -")
set theContacts to {}
repeat with thisContactID in theContactIDs
set end of theContacts to contact id thisContactID
end repeat
-- For example display the first name of the first contact
display dialog first name of (item 1 of theContacts) as string
这将为您需要的联系人进行聚光灯搜索(mdfind
命令):
mdfind命令的输出是与此查询匹配的文件列表。因此,此输出将通过管道传输到mdls
,这将列出所有可搜索的聚光灯字段,包括类别。应将简单的联系人ID列表返回给AppleScript。
然后可以使用简单的重复循环将联系人ID列表转换为联系人列表。