Making New Person in Address Book

Hello everyone! Here’s the deal: I’m trying to create some people in “Address Book” but all I managed to set is the first name, last name, note, organization and a few more. I’m having terrible trouble with address, phone, birthday, MSN, ICQ and Yahoo handle.

I searched BBS for a while

but they all talk about how to get stuff, never how to set (or at least not what I 'm looking for)

I tried a few things like:

	tell application "Address Book"
		set Nico to (item 1 of (every person whose name is "Nik"))
		get properties of address of Nico
		get properties of Yahoo handle of Nico
	end tell
	-- this to get an idea of how it works...
	tell application "Address Book"
		set Nuevo to (item 1 of (every person whose name is "Nik")) --  (was actually a 'make new person with properties:{}')
		-- set first name of Nuevo to "Nico" -- this OK
		-- set note of Nuevo to "Hello, this worked!" -- and it did...
		set properties of Yahoo handle of Nuevo to {label:"Yahoo ID", value:"nicolas_christie"} -- this runs but does nothing
		-- set street of address of Nuevo to "9 de Julio 123" -- same with this
		save addressbook
	end tell

The thing is ‘Yahoo handle’ and ‘MSN’ and ‘address’ are not properties, they’re elements of the ‘class person’ but I have no idea on how to work with those…
What I need would be something like:

		make new person with properties {first name:Nombre, last name:Apellido, organization:Compania, email:eMail_Uno, phone:Telefono, birth date:Cumple, ICQ handle:ICQ, MSN handle:MSN, Yahoo handle:Yahoo, address:{street:Direccion, zip:CP, city:Ciudad, state:Provincia, country:Pais}}

And a few of those with different labels (as you may have noticed variables in my code are in spanish, so labels should be too :wink: )
OK, thanks a lot for reading, and eventually for answering! Bye!


Elements are objects of other objects. When you look at the dictionary for the ‘person’ object you’ll see this under the Elements for the ‘address’ object:

address by numeric index, before/after another element, as a range of elements, satisfying a test, by ID

So, if you want to use a certain address of a certain person you need to reference the object. Here’s an example of a reference to an address of a certain person:

tell application “Address Book”
set first_address to first address of person “Sally Wally”
end tell

And the result is:

address 1 of person id “D3F4D6E5-A46E-11D8-B16C-000393AF3EE8:ABPerson” of application “Address Book”

It returned a reference by numeric index. It’s good to let the computer get your references for you.

On the other hand, properties don’t need references because they are properties of an object. Say I wanted to change the ‘state’ property of person “Sally Wally” above.

tell application “Address Book”
set first_address to first address of person “Sally Wally”
set state of first_address to “MyState”
save addressbook
end tell

Here, ‘state’ is a property so no index or whatever is necessary. Note that Address Book doesn’t update it’s window on the fly so you won’t see any changes until you do something like switch persons, quit the app, or use the ‘save addressbook’ command.


Thank you very much Kel! What you wrote not only helps a lot for “Address Book” but for many other doubts I had about other apps and scripting in general…