1

有没有比这更有效的方法来确定联系人是否不存在:

set theAddress to "foo@bar.com"

set found to false

repeat with aContact in contacts

  if email addresses of aContact contains theAddress then
    set found to true
    exit repeat
  end if

end repeat

if not found then
  ...
end if

如果找不到(并返回true),这将创建一个新联系人:

set found to open contact email address "foo@bar.com"

** 编辑 **

按类别搜索 Outlook 联系人表明我应该能够使用 Spotlight 查询来执行此操作:

-- the address to be found
set theEmailAddress to "foobar@acme.com"

-- search identity folder
set currentIdentityFolder to quoted form of POSIX path of (current identity folder as string)

--perform Spotlight query
set theContacts to words of (do shell script "mdfind -onlyin " & currentIdentityFolder & "  'kMDItemContentType == com.microsoft.outlook14.contact && [metadata element that represents an email address] == " & theEmailAddress & "' | xargs -I % mdls -name com_microsoft_outlook_recordID '%' | cut -d'=' -f2 | sort -u | paste -s -")

-- process results
...

代表联系人电子邮件地址的元数据元素是什么?

4

1 回答 1

0

您正在寻找的元数据元素是 kMDItemEmailAddresses - 您可以在Apple 的开发人员库中找到它以及更多内容,尽管我承认它需要大量搜索才能找到它。

对我有用的 Shell 命令(将其包装在 AppleScript 中是读者的练习):

mdfind 'kMDItemContentType == com.microsoft.outlook14.contact && kMDItemEmailAddresses == "user@example.com"'
于 2016-04-19T03:47:54.303 回答