If you are working on a server running Microsoft Exchange Server, and you have a version of Microsoft Entourage that was updated with Microsoft Office 2004 for Mac Service Pack 2 (11.2.0) or a later version, you have greatly increased functionality, including multiple calendars and address books. This gives you the option of keeping private items on your local calendar "On My Computer" and work items on the Exchange calendar, for example. But there is no way to superimpose them to see your whole schedule at once.
It would be useful to have a quick way of getting events from one calendar to the other, and the same for contacts in different address books. To actually keep them in sync would require a very complex script. But if you are content to merge all of your events by moving all events from one calendar to the other, you could actually keep this going by running the script periodically.
The following script moves all events from the local calendar "On My Computer" to the personal primary calendar on your Exchange account:
tell application "Microsoft Entourage" move (every event of calendar id 13) to primary calendar ¬ of Exchange account 1 end tell
That's it. Or, you could do it the other way around. Note that the local calendar has a fixed built-in ID: it is always
id 13. (The local address book is
address book id 14.) Underneath, they are now actually folders, because since the Office 2004 for Mac
SP2 update, calendar and address book classes are subclasses of folder. You can also refer to them as
calendar 1
and
address book 1.
The calendar class did not exist before the Office 2004 for Mac SP2 update to Entourage. The event and contact classes were elements of the application, not of the calendar and address book classes as they are now. One useful thing to know is that you can still treat events and contacts as elements of the application — so older scripts do not break — but in that case the only ones found and recognized are the events and contacts belonging to the calendar and address book associated with your default e-mail account.
If you don't have a Microsoft Exchange account, then you don't need to concern yourself with this at all, since you have only local calendar, events, address book, and contacts, and all will be found. If you do have an Exchange account, then if it is your default mail account, only your Exchange events and contacts of your primary Exchange calendar and Exchange address book will be found when you (or an older script) does not specify which one.
If you set a POP account or IMAP account as your default mail account, then only your local events and contacts "On My Computer" will be found. So you can switch from one to the other by switching the default account in Tools > Accounts > Mail. But since you are writing and editing your own scripts, you can always specify precisely which calendar or address book you mean, including all subsidiary calendars and calendar subfolders, by name or ID. If by name, you must always show the whole hierarchy:
calendar "Extra" of calendar "Calendar" of Exchange account 1.
If you have more than one Exchange account, you need to refer to each one by name (or get its ID). Doing so by index number is not reliable if you add and remove accounts, and even its ID may change (as with all objects in Entourage) if you ever rebuild the database. On the other hand, the name can be changed at any time, so ID is usually more reliable, until you rebuild.
You may be wondering about copying, rather than moving, the events. The duplicate command in the Standard Suite does not work for events to duplicate a local event in the same location (from where you could move the duplicate to the other calendar), not even without the to parameter. The error you get when you try that (Can't set event id 1295 to event id 1295) indicates that it's trying to duplicate the ID as well, which is not possible. ID is read-only, is unique, and is generated automatically when a new object is created.
It used to be impossible to move messages, contacts, or events on or to servers. This is because both the move and duplicate commands, in the Standard Suite, must return a result: namely, the moved or duplicated item. But IMAP and Exchange servers cannot be relied on to return results of new items without a timeout, so this ability was lacking.
Versions of Entourage that were updated with Office 2004 for Mac SP2 or a later version get around this problem by guaranteeing the same ID for a "moved" item, which is a new item in the new location, with the original item then deleted, as are all "moves" on computers in every context. So Entourage can return the ID result immediately "on faith" without having to wait for the server to return it. That means that behind the scenes, IDs are now copied or replaced. That can never be with a duplicated item. Both items would then have the same ID, which is impossible. Therefore, move is possible, but not duplicate.
The way to do a "copy" is to create a new event based on the properties of the old one. You could certainly get all of the properties of the original event and then make a new event at the calendar that you want with properties, and so on. That is the traditional way to do it.
However, if you wanted to do this, for example, for all 3000 events from one calendar to another, it would take a very long time because a separate AppleEvent is sent for both getting and setting every single property, even when in a
with properties
block. It would be even slower for contacts, which have about 65 properties and elements to check (perhaps you could avoid writing blank default properties).
A much faster way is to make use of the iCal data property (the equivalent for contacts is the vcard data property), which will get and make most of the properties all at one time.
The only properties you'd have to get and make separately, if they are important to you, would be the category, project list, and links properties, which are proprietary to Entourage and not included in the iCal data property. (There is also one feature, Travel Time, which is not caught either by iCal data nor by any AppleScript property.) With contacts, there is the added bonus that the vcard data property gets the picture, too, for which there is no AppleScript property.
However, you cannot make a new event from the iCal data property at an Exchange calendar, only at the local calendar. Instead, you make it at the local calendar and then move it.
Here's the script for copying one event (add your own code to check for the class of the selected item). You can omit links and project list if you don't use them.
tell application "Microsoft Entourage"
set theEvent to item 1 of (get selection)
set {iCalData, theCategories, theProjects, theLinks} ¬
to theEvent's {iCal data, category, project list, links}
set dup to make new event at calendar id 13 with properties ¬
{iCal data:iCalData, category:theCategories, project list:¬
theProjects}
repeat with i from 1 to (count theLinks)
set theLink to item i of theLinks
link theLink to dup
end repeat
move dup to primary calendar of Exchange account 1
-- or to any calendar
end tell

