Create a new contact
It is easy to make a new contact. There are no fewer than 70 properties of the contact class, 63 of which you can get using the properties property, and most of them are read-write. They all have defaults (most are
""), which do not need to be set. You can set as few properties as you want or have information for.
One thing that has changed in recent versions of Microsoft Entourage is that you have multiple address books (and calendars) if you have a Microsoft Exchange account. If that applies to you, you would now have to specify in which address book you want to make the contact, or let it be the default location.
In versions of Entourage
that were updated with Microsoft Office 2004 for Mac
Service Pack 2 (11.2.0) or later, address book and calendar are now full-fledged classes. Contacts are now elements of the address book class, not of the application as they used to be. To avoid breaking the many scripts out there that simply
make new contact
and refer to contacts by name, not in an address book, the developers have allowed the old terminology to work by assuming a default address book.
If you do not have an Exchange account, you have only one address book, which is the local one "On My Computer." If you do have an Exchange account, your default address book is the one associated with your default mail account. If that's your Exchange account, then your default address book is your primary Exchange address book. If your default mail account is a POP account or IMAP account, your default address book is your local one "On My Computer."
This means that if you don't specify a location at which to make contacts, they will still be made. If you are using a version of Entourage that predates the Office 2004 for Mac SP2 update, you must not specify a location at which to make contacts or your script will error. If you have a later version, you can specify any of them.
The way you refer to the local address book is:
address book 1, or
address book id 14. You can refer to an Exchange address book as follows:
(get primary address book) of Exchange account 1
or
address book "Extra" of address book "Contacts" ¬ of Exchange account "Name"
Or, you can use any of the usual ways (by name, index, ID, or a
whose
filter).
Note that if you have nested "subfolder" Exchange address books, the folders only show up that way (without any access to their contents) in the Entourage Mail folder list. In the Address Book, they appear in a "flat" list, so do the following:
Give your extra address books unique names.
If you have nested them as subfolders, check the folder hierarchy in Entourage Mail before writing your script.
So, at the default address book, do the following:
tell application "Microsoft Entourage"
set newContact to make new contact with properties ¬
{first name:"Phyllis", last name:"Harris", home address: ¬
{street address:"123 Main Street", city:"Sometown", ¬
state:"CA", zip:"12345", country:"USA"}, ¬
default postal address:home, home phone number:¬
"(312) 555-1234", mobile phone number:¬
"(312) 555-5678", category:{category "Family"}}
set email1 to make new email address at newContact with properties ¬
{label:home, contents:"someone@example.com"}
set email2 to make new email address at newContact with properties ¬
{label:work, contents:"someone2@example.com"}
set default email address of newContact to email1
end tellYou could just take a shortcut and set the email address property to
someone@example.com, rather than making email address elements afterwards. But then you could make only one of them that way and you couldn't set its label to home (it would be work, by default). It is a useful shortcut when there's only one email address and you want the work value for the label property.
You need to set variables (email1
and
email2) to the email address elements in order to select one of them as default email address. By default, the first one made will be the default.
There is a lot more that you can set or change for a new or existing contact. Most properties are text type, but note that children is a list. Then there are a few properties that are records like home address, and a few that are dates, namely anniversary, birthday, and the two custom date field properties.
Open a contact
Entourage
keeps a database for each identity. All of its elements are in that database, not in separate files on your computer like Microsoft Word
documents. That makes it much easier to refer to them, whether to open them or to modify them. They are almost always obtainable by ID (which you usually won't know), by index (which you won't know) — the index numbers are generally generated sequentially, in order of creation — by name (which you will know), or by
whose
filter (which you can devise).
You apply the same conditions when referring to contacts as you do when making them, with regard to location. If you do not have an Exchange
account, you can just refer to
contact
"Phyllis Harris"
— of no location. (You do have to get the name exactly right if you refer by name.)
You can do the same if the person is in your default address book, even if you have Exchange with its extra address books. However, the following does not work to reference the contact:
contact "Phyllis Harris" of address book 1
You cannot refer by name to a contact in a particular specified address book. The following works, although it's slower:
first contact of address book 1 whose name is "Phyllis Harris"
So to open that contact into its tabbed contact window, just preface any valid expression for the contact object with the command open, as follows:
tell application "Microsoft Entourage" open contact "Phyllis Harris" -- if in default address book -- or if not: open (first contact of address book 1 whose name is "Phyllis Harris") end tell


