Title: Re: Quick script help
On 11/21/03 1:36 PM, "Allen Watson" <[EMAIL PROTECTED]> wrote:

> On or near 11/21/03 1:20 PM, Russell  Fabry at [EMAIL PROTECTED]
> observed:
>
>> X-Mailer: MIME::Lite 1.2  (F2.71; T1.001; A1.51; B2.12; Q2.03)
>> Can someone tell me the Applescript syntax for adding specific recipients
>> to an open message? (i.e. to have the script automatically add
>> [EMAIL PROTECTED])
>
> Assuming you are talking about a draft window, you can do it. Here's a
> writeup by Paul Berkowitz that I saved some time back:
>
>> Although Entourage and OE are implemented in
>> Unicode, unless you actually need it for multilingual operations or 2-byte
>> languages (in which case just use AppleScript's "as Unicode"), you can treat
>> all text as text. So if you're making a draft window you can simply say:
>>
>> tell application "Microsoft Entourage"
>>     activate
>>     set myNewMsg to make new draft window
>>     set myToAddress to  "<[EMAIL PROTECTED]>"
>>     set to recipients of myNewMsg to myToAddress
>>     set subject of myNewMsg to myToAddress
>> end tell
>>
>>
>> Making outgoing messages,
   ...etc.

Thanks for quoting me, Allen. Here Russell wants to add more recipients to a draft window. This is quite easy, as opposed to trying to add recipients to a saved 'outgoing message', which is actually impossible, not just difficult!

In a draft window (new message window open on the screen), you add recipients by replacing the 'to recipients' string you have there already (which might be "[EMAIL PROTECTED]", or "John Smith <[EMAIL PROTECTED]>") by a comma-delimited string of as many of these as you want;

    set myToAddresses to "[EMAIL PROTECTED], John Smith <[EMAIL PROTECTED]>"

Notice there are no end-quotes in the middle of the string, no list braces, etc.  It doesn't matter if there's a space after the comma or not:

    set myToAddresses to "[EMAIL PROTECTED],John Smith <[EMAIL PROTECTED]>"    

but it looks better if there is! One very important thing is that if there's any punctuation in a display name, such as "John H. Smith" you absolutely need to have internal quotes around the display name or the whole thing is messed up. Therefore it's best to _always_ include them in a display name. Internal quotes (inside a string) in AppleScript need escaping, of course, as \".

So the individual components of these strings can look like any of these:

    "[EMAIL PROTECTED]"
    "<[EMAIL PROTECTED]>"
    "\"Display Name\" <[EMAIL PROTECTED]>"

To add one more recipient to an existing set of to recipeunts - or to a blank To recipient field, you'd do this:


tell application "Microsoft Entourage"
    set newMsg to front window
    if class of front window ≠ draft window then
        beep
        return
    end if
    
    set newRecip to "\"John H. Smith\" <[EMAIL PROTECTED]>"
    set toRecips to (to recipients of newMsg)
    if toRecips ≠ "" then set toRecips to toRecips & ", "
    set (to recipients of newMsg) to (toRecips & newRecip)
end tell



If you're planning to add a whole lot of new recipients, then it's easier to put them in a list and do it this way:


tell application "Microsoft Entourage"
    set newMsg to front window
    if class of front window ≠ draft window then
        beep
        return
    end if
    
    set newRecips to {"\"John H. Smith\" <[EMAIL PROTECTED]>", "\"Mary Jones\" <[EMAIL PROTECTED]>", "[EMAIL PROTECTED]"}
    set toRecips to (to recipients of newMsg)
    set AppleScript's text item delimiters to {", "}
    set toRecips to (toRecips & newRecips) as Unicode text   -- a Unicode string with commas
    set AppleScript's text item delimiters to {""}
    set to recipients of newMsg to toRecips
end tell





--
Paul Berkowitz
MVP Entourage
Entourage FAQ Page: http://www.entourage.mvps.org/toc.html

PLEASE always state which version of Entourage you are using - 2001 or X. It's often impossible to answer your questions otherwise.

--
Paul Berkowitz
MVP Entourage
Entourage FAQ Page: http://www.entourage.mvps.org/toc.html

PLEASE always state which version of Entourage you are using - 2001 or X. It's often impossible to answer your questions otherwise.

Reply via email to