0

我注意到我的 OS X 10.8.5 联系人中有许多(数百个)重复的字段名称和值。“字段名称和值”可能不是正确的词,但我的意思是,我有许多联系人卡片似乎具有相同的字段,如下所示:

在此处输入图像描述

问题不仅限于社交资料电子邮件地址电话和(可能还有更多)也会出现重复。

昨天我被介绍给 AppleScript,虽然我确实了解了一点(可以运行它们,可以玩一些现有的脚本,知道save:)),但这仍然超出了我的能力:

如果它们具有相同的类型(?)和相同的标签(?)相同的值(?),那么这样的 AppleScript 会真正帮助我删除每张卡的重复字段。(但保留一个实例。)

我可以想象地址(包括街道、邮政编码等)可能要求太多。但是,非复合“字段”已经大大清理了我的通讯录。

为肯定没有正确使用技术术语而道歉。

4

1 回答 1

1

这是一个例子。仅在我制造重复字段的两个联系人上进行了测试。并将它们放在一个组中进行测试

这应该让您了解构建代码的一种方法。

这个例子就是这样,因为我不想花太多时间在上面。但在我的测试中工作。

该示例将删除联系人中重复的社交资料和电话号码字段。

在社交资料中重复删除操作。这是因为第一次删除会强制 contacts.app 将条目替换为社交媒体网站的 URL。

从这里开始,其他领域的建设应该相对容易。

每组字段,即电话、社交资料、电子邮件都应该有自己的运行处理程序,以使代码更易于管理。就像我在这里所做的那样。

您还应该注意,对大量联系人执行此操作可能需要很长时间。

在玩任何这些之前,您还应该备份通讯录联系人。使用风险自负

set targetGroup to "BD"


tell application "Contacts" to set thePeople to people of group targetGroup -- TEST GROUP OF PEOPLE
---- tell application "Contacts" to set thePeople to people  -- ALL PEOPLE 

(* Run the Handler for  Social profiles*)
my deleteSocialEntries(thePeople)

(* Run the Handler for  phones *)
my deleteSocialPHONE(thePeople)

(* Handlers*)
on deleteSocialPHONE(thePeople)

    tell application "Contacts"




        (* iterate over the people - get each person in the contacts*)
        repeat with i from 1 to number of items in thePeople
            set this_person to item i of thePeople

            (*get all the phones of the person*)
            set theFields to (properties of phones of this_person)


            set keepers to {}
            (* iterate over the phones and get a phone's value*)
            repeat with i from 1 to number of items in theFields
                set this_item to item i of theFields
                set thisValue to value of this_item

                if thisValue is not in keepers then
                    (* Not in the list of keepers so add it*)
                    copy thisValue to end of keepers

                else
                    (* Was already  in the list of keepers try and delete it*)
                    try
                        set thisID to id of this_item
                        set thisD to (every phone of this_person whose id is thisID)

                        delete (item 1 of thisD)

                        save
                    end try
                end if


            end repeat

        end repeat
    end tell

end deleteSocialPHONE


on deleteSocialEntries(thePeople)
    set social to {"Twitter", "Linkedin", "Facebook"}
    tell application "Contacts"




        (* iterate over the people - get each person in the contacts*)
        repeat with i from 1 to number of items in thePeople
            set this_person to item i of thePeople

            (* iterate over the social media types for this person *)
            repeat with i from 1 to number of items in social
                set this_soc to item i of social
                (*get all the *type* of social profiles of the person*)
                set theFields to (properties of every social profile of this_person whose service name is this_soc)

                set keepers to {}
                (* iterate over the ocial profile  and get a user name value*)
                repeat with i from 1 to number of items in theFields
                    set this_item to item i of theFields
                    set thisValue to user name of this_item

                    if thisValue is not in keepers then
                        copy thisValue to end of keepers
                    else
                        (* Was already  in the list of keepers try and delete it*)
                        set thisID to id of this_item
                        set thisD to (every social profile of this_person whose id is thisID)

                        delete (url of item 1 of thisD)
                        delete (user name of item 1 of thisD)

                        delete (url of item 1 of thisD)
                        delete (user name of item 1 of thisD)
                        save

                    end if
                end repeat

            end repeat

        end repeat
    end tell

end deleteSocialEntries
于 2013-09-15T14:54:32.287 回答