2

有没有办法在 Outlook 2011 for Mac 中按类别搜索联系人?

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
4

1 回答 1

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 列表转换为联系人列表。

于 2013-09-17T21:26:27.677 回答