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 124
You need to set variables (email1, 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.)
There is a lot more you can set for contact, or can change on an existing contact – have a go. Almost all properties are text type, but note that children is a list. Then there are a few properties that are records like the home address made above, and a few that are dates, namely anniversary, birthday and the two custom date fields.
Open an Existing Contact
Entourage keeps a database for each identity. All its elements are in that database, not in separate files on your computer like 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 – generally in order of creation (which you won‘t know), by name (which you will know), or by whose filter (which you can devise).
The same conditions apply to referring to contacts as to making them, with regard to location. If you do not have an Exchange account, you can just refer to contact "Joe A. Blow" – of no location. (You do have to get the name exactly right if you refer by name.) You can do the same if he is in your default address book, even if you have Exchange with all its extra address books. However, this does not work to reference the contact:
contact "Joe A. Blow" of address book 1
(I hope this is made to work for a later version. It seems to me to be a bug.) You cannot refer by name to a contact in a particular specified address book. But this works, though slower:
first contact of address book 1 whose name is "Joe A. Blow"
So to open that contact into its tabbed contact window, just preface any valid expression for contact with the command open:
tell application "Microsoft Entourage"
open contact "Joe A. Blow" -- if in default address book
-- or if not:
open (first contact of address book 1 whose name is "Joe A. Blow")
end tell
Invert Contact Names
Occasionally you'll find that you've created a contact via 'Add to Address Book' from a message where the sender was using an email client that puts the last name before the first name, like so: LastName, FirstName. Worse, you may have imported hundreds of contacts of this type from some other program. Entourage does not understand this format and puts the LastName, plus the comma, into the First Name field, and LastName into the First Name field, and then sorts by the (real) FirstName placed last – a mess. A simple script will put that right:
tell application "Microsoft Entourage"
set backToFronts to every contact whose ¬
first name ends with ","
repeat with theContact in backToFronts
tell theContact
set {realFirst, realLast} to {last name, first name}
try
set realLast to text 1 thru -2 of realLast
on error
set realLast to ""
end try
set {first name, last name} to {realFirst, realLast}
end tell
end repeat
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine