【问题标题】:Search Outlook contacts by category按类别搜索 Outlook 联系人
【发布时间】:2013-09-19 01:06:12
【问题描述】:

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

【问题讨论】:

    标签: applescript


    【解决方案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 列表转换为联系人列表。

    【讨论】:

    • +1 - 为了让你的脚本正常工作,我必须使用set theCategory to item 1 of (every category whose name = "Recruiter") 来获取类别对象;有捷径吗?一个相关的问题,查询返回Listctxt 对象。有没有办法将它们投射到contact
    • 回答第一个问题,我认为这是不可避免的,因为谁的子句总是会返回一个列表。在这种情况下,我们保证只有一个类别的名称 =“招聘人员”,因此我们只需查看该列表的第 1 项。此列表也可能为空(如果没有名称 = "Recruiter" 的类别),因此健壮的代码也应该针对这种可能性进行防御性编码。
    • 为了回答第二个问题,我编辑了我的答案。可以简单地迭代联系人 ID 列表以获得联系人列表。
    猜你喜欢
    • 2010-10-23
    • 2013-09-07
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多