按类别搜索Outlook联系人

时间:2013-09-17 20:18:43

标签: applescript

有没有办法按类别在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

1 个答案:

答案 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命令):

  • 它只会查看您当前的身份文件夹
  • 只会查找联系人
  • 它只会返回标有“招募者”类别ID
  • 的联系人

mdfind命令的输出是与此查询匹配的文件列表。因此,此输出将通过管道传输到mdls,这将列出所有可搜索的聚光灯字段,包括类别。应将简单的联系人ID列表返回给AppleScript。

然后可以使用简单的重复循环将联系人ID列表转换为联系人列表。