Script to create iPhone Contacts

Solution 1:

An Applescript can bulk-create OS X address book entries, which you can then import to your iPhone. I made up a basic one for you:

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

Open AppleScript Editor (in your Applications/Utilities/ folder) and paste that in to a new script. As is, it will make you 5 numbered contacts like so: example contacts

You can change the number in the set numberOfEntries to "5" as integer line to however many you need, and change the data if you wish. If you need other fields (like phone numbers), ask and I can show you how.

Improved version

I went a bit overboard and made a version that comes up with nicer names. I took the 20 most popular male and female names, 40 most popular last names, and added a middle initial, so you get a pretty low chance of duplicates (a bit under 5% in a set of 2000, by my math) without the goofy looking numbered contacts.

It also adds all the contacts to a group ("Test Group") so you can pick out all the dummy ones easily if you're adding to an existing address book and want to clean it up later.

Edit: I also changed it to prompt for how many items to create, so it's not necessary to edit the code.

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

Here's what it generates: dummy contacts 2

Solution 2:

I have used Rob's code in shorter form to create an Automator Service that lets you right-click on an email and create a contact:

enter image description here

Thanks very much Rob - you've saved me hours and hours of work :-)