Microsoft Entourage has no setting to attach your vCard to outgoing messages. You can drag your me contact from the Address Book to the message every time, but that soon becomes tedious. Instead, you can run the following script, which also uses AppleScript's read/write commands and some Finder scripting to update your vCard, and then attach it. If want to send your vCard with every message, set the script to run from a repeating schedule every one minute.
tell application "Microsoft Entourage"
set MUDpath to (path to MUD) as Unicode text
set meContact to me contact
set vcInfo to vcard data of meContact
set myname to name of meContact
end tell
set pathName to (MUDpath & myname & ".vcf") as Unicode text
try
set f to open for access file pathName with write permission
--will create a new one or update every time
set eof f to 0
write vcInfo to f
close access f
tell application "Finder"
set creator type of file pathName to "OPIM"
set file type of file pathName to "vCrd"
end tell
set theVcard to alias pathName
on error errMsg number errNum
try
close access f
end try
beep 2
return
end try
tell application "Microsoft Entourage"
try
if class of window 1 ≠ draft window then error number -128
on error
return
end try
set newMsg to window 1
set theAttachments to every attachment of newMsg
repeat with theAttachment in theAttachments
-- only one, don't multiply vCards
if name of theAttachment = (myname & ".vcf") then return
end repeat
make new attachment at newMsg with properties {file:theVcard}
end tellThe first part of the script gets the path to MUD, the path to the Microsoft User Data folder, where you are going to store your vCard. Although you don't realize it when you make vCards in the UI, Entourage must have it as a file on your hard disk to be able to make an attachment to a message. You could make it in the Entourage Temp subfolder there, where Entourage makes vCards that are dragged to a message, but instead, using this script, you can make it right in the MUD folder to have it easily available in the UI, too.
Entourage requires (and won't let you delete) a me contact, so the line that gets it will never error. There is a property of contact called vcard data, which contains all the data in text form, that makes up a vCard. You also need the name of your me contact to become the name of the vCard.
The next section of the script, after the first Entourage block, creates the vCard file. First you compose the full path of the file that you are creating: the path to MUD, plus your name, plus the .vcf extension.
The next group of commands comes from the Standard Additions whose dictionary you can find in Macintosh Script Editor. Find the File Read/Write Suite.
To write to a file, you need to
open for access file [pathname] with write
permission. That creates a new file if it doesn't exist yet, or accesses it if it does. The command
set eof f
to 0
erases it (you are about to update the vCard, which might have out-of-date information from the last time). You then write the vcard data to the file and close it. Always put a write command inside a
try/error
block, and try to
close access
the file if there's any sort of error. It is not recommended that you leave a file with open access.
On most Macintosh
computers, the Address Book that comes with the operating system is the default "owner" of .vcf (vCard) files. So the file would appear with the Address Book program's vCard icon. You must tell the Finder to set the file's creator type to OPIM — the Entourage
4-character signature (creator type). Also tell the Finder to set its file type to
vCrd
to get the correct Entourage
icon, which is vCard, not database, message folder, or anything else.
Back in Entourage, check that the front window is a draft window and check for existing attachments. If the script is running from a schedule every one minute, you don't want it multiplying the vCard by adding a new copy every minute. So if you find that there already is an attachment with your name and
.vcf, you quit the script (return) without doing anything. Otherwise, proceed to make a new attachment at the draft window using the alias object as the file property for the attachment. Whenever you send off the message, it will take your vCard with it.
Using a reverse process, you could make new contacts in your Entourage
Address Book by running a script (possibly from a mail rule filtered on messages with attachments whose names contain
.vcf) to save .vcf file attachments to your hard disk. For example, you could save them in a subfolder for vCards in the MUD folder, or somewhere temporary, and then delete the files at the end of the script. Then use the read command to read
as Unicode text
the file into an
r
variable and then, in Entourage,
make
new contact with properties {vcard data:r}.
However, this script could backfire if the vCard was sent using the Mail and Address Book applications that come with the operating system, or some other applications that make vCards differently. Entourage
uses Unicode text, which is why writing the vcard data worked well and why you need to read it back
as Unicode text. However, other applications on the Macintosh
write vCards as plain text (string).
In addition, the Address Book that comes with the operating system now follows a different protocol, so it cannot be adjusted for Entourage. If you read one of those vCards as Unicode text, the resulting Entourage contact appears to be completely blank.
The following option should work, given that Entourage is the only application with Unicode vCards. A short test that checks for the presence of a byte-order mark (BOM) of hex-characters FEFF — ASCII characters 254 and 255 — as the first two characters of the text should suffice. If the text begins with the BOM, it's Unicode UTF-16 as made by Entourage vCards; if not, it's a plain text vCard that is not compatible with Entourage.
set r to read theVcard -- an .vcf alias (file) on your computer
if (ASCII number (character 1 of r2)) = 254 and ¬
(ASCII number (character 2 of r2)) = 255 then -- checks for Unicode
set r to read theVcard as Unicode text -- gets the data correctly
tell application "Microsoft Entourage"
make new contact at address book 1 with properties {vcard data:r1}
end tell
else
beep
display dialog "This vCard is not from Entourage and cannot be " & ¬
"imported as a contact. Sorry." buttons {"OK"} default button 1 ¬
with icon 0
end if

