几个星期前,我偶然在朋友的iPhone上添加了大约600个联系人到我的Mac地址簿。不幸的是,我没有备份我的联系人,现在他们都与我的iPhone和iCloud同步。 我能够将所有不需要的联系人导出为" .vcf"来自我的朋友电话的文件,所以我有约600个文件,如" John Doe.vcf"以及只有联系人姓名的纯文本列表。
理想情况下,我想要一个与VCF文件中的数据匹配的脚本,以确保我删除了正确的联系人。
想法#2将删除与列表中的名称匹配的联系人,跳过返回两个或更多结果的搜索(这样我不会丢失与我的朋友同名的自己的联系人)
我开始尝试使用以下AppleScript删除单个联系人,但没有运气。请帮忙!
set daName to "John Doe"
tell application "Contacts"
repeat with onePerson in people
if (value of name of onePerson) is daName then
delete onePerson
end if
end repeat
end tell
- UPDATE -
这是我用来执行任务的最终代码。我在顶部添加了一个循环,循环遍历剪贴板中复制的名称列表。我还在对话框中添加了重复联系人的姓名,以便我注意到它。
提示:
最终法典
set the clipboard to (the clipboard as text)
set the_strings to the clipboard
repeat with this_string in paragraphs of the_strings
set daName to this_string
DeleteContact(daName)
end repeat
on DeleteContact(theName)
tell application "Contacts"
set myList to every person whose name is theName
set Nb to count of myList
if Nb = 0 then return -- no record found
if Nb > 1 then
display dialog theName & " (too many found: do nothing)"
else
set myperson to item 1 of myList -- only 1 found to be deleted
delete myperson
save
end if
end tell
end DeleteContact
答案 0 :(得分:0)
下面的脚本包含检查名称和删除的子程序。我添加了一些注释,以便更容易适应您的需求:您可以构建一个循环来查找您的卡并调用DeleteContact子例程。
set daName to "John Doe"
DeleteContact(daName)
on DeleteContact(theName)
tell application "Contacts"
set myList to every person whose name is theName
set Nb to count of myList
if Nb = 0 then return -- no record found
if Nb > 1 then
display dialog "too many found: do nothing"
else
set myperson to item 1 of myList -- only 1 found to be deleted
delete myperson
save
end if
end tell
end DeleteContact
如果在多个联系人中存在相同的名字,我会显示一个对话框,但由你决定在这里做什么。
答案 1 :(得分:0)
吉奥
这是我的一个脚本,它可以解决您的问题,尽管您从未说过问题是什么。
tell application "Contacts"
local results,dlist,dloop
set results to {}
set dlist to people whose (first name contains "Oxnard" or (last name is equal to "Abercrombe"))
repeat with dloop in dlist
delete dloop
end repeat
set end of results to "Records deleted :" & count of dlist
save
return results
end tell
请注意,“联系人”词典确实定义了name
属性,但它将基于首选项设置。