script to fill in fields in Address Book

Hi, I’m totally new to this forum and AppleScript. All I want is to make a script that, when I’m entering a new contact in Address Book, would automatically populate the city, state & zip fields for me. Most of the contacts I enter are in the same town, so it gets repetitive.

I tried reading the AppleScript Language Guide, but my brain started to hurt. I did search these forums and scriptbuilder, but couldn’t find what I’m looking for.

Most of the examples I could find involved getting information from Address Book, not putting information into it, or putting info in from other files or emails.

I know this is pathetic, but this is what I have so far. Of course it doesn’t work. How do I tell Address Book to perform these actions on the current contact? What is the proper syntax to set the city, state, and zip fields? I don’t really understand elements, properties, objects, etc.

tell application "Address Book"
	set theCity to "Anytown" as string
	set theState to "NY" as string
	set theZip to "11111" as string
	set city to theCity
	set state to theState
	set zip to theZip
end tell

I’m sure this would really be very simple if I knew what I was doing. Thanks in advance for any help!

Jennifer

Browser: Firefox 3.0.12
Operating System: Mac OS X (10.5)

Hi,

it’s quite easy. The top element is the application (Address Book).
A contact is an element of the application.
A contact has elements like addresses, emails, phones
An address has properties like city, street, zip.
To change a property you have to reference e,g,

city of address 1 of contact "myContact" of application "Address Book"

There is no current contact. But you can select one or more contacts and run the script
This script changes all addresses of the selected contacts to the specified values


property theCity : "Anytown"
property theState : "NY"
property theZip : "11111"

tell application "Address Book"
    set theSelection to selection
    repeat with oneContact in theSelection
        repeat with oneAddress in (get addresses of oneContact)
            tell contents of oneAddress
                set city to theCity
                set state to theState
                set zip to theZip
            end tell
        end repeat
    end repeat
end tell