Macos 使用AppleScript和mdfind通过电子邮件搜索Outlook联系人

Macos 使用AppleScript和mdfind通过电子邮件搜索Outlook联系人,macos,applescript,spotlight,outlook-2011,Macos,Applescript,Spotlight,Outlook 2011,有没有比这更有效的方法来确定联系人是否不存在: 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 .

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

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
):

**编辑**

建议我应该能够使用聚光灯查询来执行此操作:

-- 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
...

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

您要查找的元数据元素是kMDItemEmailAddresses——您可以在上找到它,甚至更多,尽管我承认需要进行大量搜索才能找到它

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

-- 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
...
mdfind 'kMDItemContentType == com.microsoft.outlook14.contact && kMDItemEmailAddresses == "user@example.com"'