Moving from Microsoft Office VBA to AppleScript:
MacTech's Guide to Making the Transition
Introduction
|
Table of Contents
Page Prev and Page Next buttons at bottom of the page.
|
April, 2007
Page 123
Contacts and Groups (Address Book)
Make a New Contact
It is a simple matter to make a new contact. There are no fewer than 70 properties of contact (63 of which you can get via the handy property properties), and almost all of them are read-write. Fortunately, you don't have to set all of them! They all have defaults (almost all of which 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 the latest versions of Entourage is that you have multiple address books (and calendars) if you have an Exchange account. (I would not be surprised if this were coming for local address books too in a later version.) 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. (More on default location in a moment.)
As of Entourage 2004 v11.2, address book and calendar are now fully-fledged classes. Contacts are now elements of address book, not of the application as they used to be. In order not to break all the many scripts out there which simply make new contact and refer to contracts by name, not in an address book, the developers have cleverly 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, 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 or IMAP account, your default address book is your local one "On My Computer".
That means that you can still not specify a location at which to make contacts (and if you are still pre-v11.2 you must not do so, or your script will error) and they will still be made. If you have v11.2 or later, you can specify any of them. The way you refer to the local address book is
address book 1
or
address book id 14
The way you refer to an Exchange address book could be
(get primary address book) of Exchange account 1
or
address book "Extra" of address book "Contacts" ¬
of Exchange account "Name"
or any of the usual ways (by name, by index, by ID, by a whose filter).
Note that if you have nested "subfolder" Exchange address books as in the last example, they only show up that way (without any access to their contents) in the Folders List in the Mail area of Entourage. In the Address Book area they appear in a "flat" list. This is not Outlook. So 1) give your extra address books unique names and 2) if you have nested them as subfolders, you'll need to check the folder hierarchy in the Mail area before writing your script.
So, at the default address book:
tell application "Microsoft Entourage"
set newContact to make new contact with properties ¬
{first name:"Joe A.", last name:"Blow", home address:{street address:¬
"123 Main Street", city:"Plainsville", state:"CA", zip:¬
"98765", country:"USA"}, default postal address:¬
home, home phone number:"(312) 555-1212", mobile phone number:¬
"(312) 555-2323", category:{category "Family"}}
set email1 to make new email address at newContact with properties ¬
{label:home, contents:"jblow@aol.com"}
set email2 to make new email address at newContact with properties ¬
{label:work, contents:"jblow@jblowindustries.com"}
set default email address of newContact to email1
end tell
Now you could just take a shortcut and set the email address property to "jblow@aol.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 and quick shortcut when there's only one email address and you're happy for it to have the Work label.
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine