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 110
save frontDoc in filePath
else -- already saved as file, can't re-save (bug)
beep
display dialog "Due to a bug in PowerPoint, you need to make sure you " & ¬
"have saved the presentation first." & return & return & ¬
"If you have done so, click \"Proceed\"." buttons ¬
{"Cancel", "Proceed"} with icon 2
set filePath to full name of frontDoc
end if
end tell
(You'll note that PowerPoint has another bug. Hopefully, that will be fixed in Office 2008 and you can then remove the display dialog and replace the else section by the same as the equivalent bit in the Excel code.)
Make a Draft Window (message window open on screen)
OK, now that we have the filePath of the front document (as text) we can proceed to make our email message. If we want to open a new message in Entourage, preset to recipients "My Boss" whose email address is "myboss@myCompany.com" and "His Boss", email address "hisboss@myCompany.com", and include a CC to "My Colleague", email address "mycolleague@myCompany.com", with a salutation ("Hi, Everyone") in place, a subject "Today's File", and your usual default signature, the script would now continue:
tell application "Microsoft Entourage"
activate
set mySigType to default signature type of default mail account
if mySigType is other then set mySig to default signature choice ¬
of default mail account
set newMsg to make new draft window with properties ¬
{subject:"Today's File", to recipients:¬
"My Boss <myboss@myCompany.com>, " & ¬
"His Boss <hisboss@myCompany.com>", CC recipients:¬
"My Colleague <mycolleague@myCompany.com>", content:¬
"Hi, Everyone" & return & return, signature type:¬
mySigType, attachment:alias filePath}
if mySigType is other then set other signature choice of newMsg to mySig
end tell
Note that we activate Entourage to bring it to the front, and that we have to extract the default signature of the default account to be able to use it when we make a new draft window. Checking the dictionary for any type of mail account (POP account, IMAP account, Hotmail account, Exchange account) you will notice that the default signature type might be random, none or other. other is the regular sort of signature: in that case you also have to extract the other signature choice, which is the actual signature. But if your account uses a random or none type, then there is no other signature choice, so we can't specify it later when making the new draft window or the script will error.
The need to use short lines with the continuation character ¬ in this article obscures the fact that the to recipients property (and cc recipients and bcc recipients properties as well) is just a continuous, single string, with the various recipients separated by commas. I.e., when you write your own scripts you wouldn't bother with the continuation character ¬ and would let Script Editor wrap the whole make new draft window command, with the to recipients property specified as:
to recipients:"My Boss <myboss@myCompany.com>, His Boss <hisboss@myCompany.com>"
You do not need to include the display names if you don‘t want to, for any recipients, and in that case you don't need the < > angled brackets around the email address either. So the line above could be written as:
< Previous Page Next Page>
- SPREAD THE WORD:
- Slashdot
- Digg
- Del.icio.us
- Newsvine