Search Outlook contacts by category

可紊 提交于 2019-12-08 00:05:47

问题


Is there a way to search for Contacts in Outlook 2011 for the Mac by Categories?

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:


I think there may be some bugs/features in the OL dictionary implementation with regard to categories - I think your search statement should work, but I agree it doesn't.

One workaround to this is to do a spotlight search instead. This may even be preferable, because it is probably faster than using the OL dictionary. In short, replace your set theContacts to ... line with the following:

    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

This will do a spotlight search (mdfind command) for the contacts you require:

  • It will only look in your current identity folder
  • It will only look for contacts
  • It will only return contacts which are marked with the id of the "Recruiter" category

The output of the mdfind command is a list of files which match this query. So this output is piped to mdls, which will list all spotlight-searchable fields, including category. A simple list of contact IDs should be returned to applescript.

The list of contact IDs can then be converted to a list of contacts with the simple repeat loop.



来源:https://stackoverflow.com/questions/18859148/search-outlook-contacts-by-category

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!