创建iPhone联系人的脚本


8

有谁知道一种使用定义数量的联系人创建联系人列表的方法吗?它们可以是虚拟条目,但是我只需要创建一个包含> 2000个条目的地址簿即可。我想到的是Automator脚本,但是我不确定该怎么做。

如果位置错误,我深表歉意。正在考虑使用SU或SE,但我想从这里开始。

Answers:


11

Applescript可以批量创建OS X通讯簿条目,然后可以将其导入到iPhone。我为您准备了一个基本的:

-- Change these to your desired data
set firstName to "Test"
set lastName to "User"
set numberOfEntries to "5" as integer

set counter to "1" as integer
tell application "Address Book"
    repeat numberOfEntries times
        set thePerson to make new person with properties {first name:firstName, last name:lastName & " " & counter}
        make new email at end of emails of thePerson with properties {label:"Work", value:"test" & counter & "@example.com"}
        make new address at end of addresses of thePerson with properties {label:"Home", city:"Fakeville", street:(counter as string) & " Some St."}
        set counter to counter + 1
    end repeat
    save
end tell

打开AppleScript编辑器(在您的Applications/Utilities/文件夹中)并将其粘贴到新脚本中。照原样,它将为您提供5个编号如下的联系人: 示例联系人

您可以将行中的数字更改为所需的数量set numberOfEntries to "5" as integer,并根据需要更改数据。如果您需要其他字段(例如电话号码),请询问,我可以告诉您如何。

改进版

我有些落伍,做了一个带有更好名字的版本。我选择了20个最受欢迎的男性和女性名字,40个最受欢迎的姓氏,并添加了一个中间的名字首字母,因此重复的几率很小(按我的数学,在2000年一组中,5%以下)高飞的编号联系人。

它还会将所有联系人添加到一个组(“测试组”)中,因此,如果要添加到现有地址簿中并希望稍后进行清理,则可以轻松挑选出所有虚拟联系人。

编辑:我也将其更改为提示要创建多少个项目,因此无需编辑代码。

-- name lists: 20 most popular (US) male and female first names, 40 most popular last names
set firstNameList to {"Mary", "Patricia", "Linda", "Barbara", "Elizabeth", "Jennifer", "Maria", "Susan", "Margaret", "Dorothy", "Lisa", "Nancy", "Karen", "Betty", "Helen", "Sandra", "Donna", "Carol", "Ruth", "Sharon", "James", "John", "Robert", "Michael", "William", "David", "Richard", "Charles", "Joseph", "Thomas", "Christopher", "Daniel", "Paul", "Mark", "Donald", "George", "Kenneth", "Steven", "Edward", "Brian"}
set lastNameList to {"Smith", "Johnson", "Williams", "Jones", "Brown", "Davis", "Miller", "Wilson", "Moore", "Taylor", "Anderson", "Thomas", "Jackson", "White", "Harris", "Martin", "Thompson", "Garcia", "Martinez", "Robinson", "Clark", "Rodriguez", "Lewis", "Lee", "Walker", "Hall", "Allen", "Young", "Hernandez", "King", "Wright", "Lopez", "Hill", "Scott", "Green", "Adams", "Baker", "Gonzalez", "Nelson", "Carter"}
set initialList to "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
set counter to "1" as integer

-- prompt for how many contacts to create
set dialogText to "Number of contacts to create?"
repeat
    display dialog dialogText default answer ""
    set numberOfEntries to text returned of result
    try
        if numberOfEntries = "" then error
        set numberOfEntries to numberOfEntries as number
        exit repeat
    on error

    end try
end repeat

-- populate the address book
tell application "Address Book"
    set theGroup to make new group with properties {name:"Test Group"}
    repeat numberOfEntries times
        set firstName to some item of firstNameList
        set lastName to some item of lastNameList
        set middleInitial to some item of initialList & "."
        set thePerson to make new person with properties {first name:firstName, middle name:middleInitial, last name:lastName}
        make new email at end of emails of thePerson with properties {label:"Work", value:firstName & middleInitial & lastName & "@example.com"}
        make new address at end of addresses of thePerson with properties {label:"Home", city:"Fakeville", street:(counter as string) & " Some St."}
        add thePerson to theGroup
        set counter to counter + 1
    end repeat
    save
end tell

这是生成的内容: 虚拟触点2


1
看起来很完美!谢谢!我会对其进行测试,并告诉您是否需要其他任何功能!
托马斯

老兄,我希望我可以+1000付出额外的努力。再次感谢!!!
Thomas

不用客气,很高兴它很有用。有时候,只编写一个小脚本来解决一个问题就很有趣。
robmathers 2012年

1
我更改了“改进的”版本,以提示生成联系人数量,而不是要求编辑脚本。
robmathers 2012年

4

我使用了罗伯(Rob)的较短格式的代码来创建Automator Service,该服务使您可以右键单击电子邮件并创建联系人:

在此处输入图片说明

非常感谢Rob-您为我节省了很多时间:-)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.