Coordinating from and to addresses

D

Daiya Mitchell

I have about 7 accounts set up in Entourage (office 11.1.1, os 10.3.9).
There are certain addresses that I always want to use to email certain
people. Is there any way to develop something that would coordinate this
for me, or does something already exist?

Say, a script that triggers on Send, and if the address meets a particular
criteria, it sets the from address to a certain account. The criteria, as
far as I am concerned, could be based on individual listings, categories, or
domains. Actually, it looks as though I could set an outgoing rule to run
an applescript on certain categories, but how would the applescript work?

This is particularly annoying when sending attachments from within Word, as
that command always uses my default work address but half the time I am
sending documents to friends I want to use my social address with.
 
B

Barry Wainwright

I have about 7 accounts set up in Entourage (office 11.1.1, os 10.3.9).
There are certain addresses that I always want to use to email certain
people. Is there any way to develop something that would coordinate this
for me, or does something already exist?

Say, a script that triggers on Send, and if the address meets a particular
criteria, it sets the from address to a certain account. The criteria, as
far as I am concerned, could be based on individual listings, categories, or
domains. Actually, it looks as though I could set an outgoing rule to run
an applescript on certain categories, but how would the applescript work?

This is particularly annoying when sending attachments from within Word, as
that command always uses my default work address but half the time I am
sending documents to friends I want to use my social address with.

I have a script that runs once a minute and checks the frontmost window. If
it is a draft message window it will check the category of the recipients,
and set the account of the message appropriately.

-- Set Account by Category v1.0 (11th March 2004)
-- created by Barry Wainwright based on an original script by Paul Berkowitz
-- Barry Wainwright <[email protected]>
-- This script will set the account of a draft message window according to
the category of it's recipients


-- to be most effective, set the script to run from a schedule every minute.

-- set up additional copies of this script to set a different account for
other categories,
-- but beware!: it operates on the first match it comes to, so different
copies
-- of this script checking other categories could cause a loop to be
repeated. This would
-- result in the account being changed every time the script runs.

-- see the 'ReadMe' for additional details

-- version history:
-- v1.0.0 - First Release, 11th March 2004


property recipientCategory : missing value -- draft messages 'to' people in
this category will be processed
property defaultAccount : missing value -- this will hold the account to set
the message to use

on run -- Main Script Routine
if (my checkRecipientCategory()) < -1 then return -- checks the category
is set up
if my checkDefaultAccount() < -1 then return -- checks the account is
set up

tell application "Microsoft Entourage"
-- Process the front window
set frontWindow to window 1
if class of frontWindow is not draft window then return -- only do
something if there's a new draft window open
set oldTIDs to AppleScript's text item delimiters
set AppleScript's text item delimiters to {","}
set theRecips to (text items of (get to recipients of frontWindow))
& (text items of (get CC recipients of frontWindow))
set AppleScript's text item delimiters to {"<"}
repeat with aRecip in theRecips -- try each recipient in turn
set theRecip to last text item of aRecip -- try and get the
email address
if theRecip ends with ">" then set theRecip to text 1 thru -2 of
theRecip -- it was a full email addres, remove the last brace
set theContacts to find theRecip -- do any contacts have this
email address?
repeat with aContact in theContacts -- there could be more than
one, loop through them
set contactCategory to category of aContact -- get the
categories of the contact
if {recipientCategory} is in contactCategory then -- do they
contain the required category?
-- found a matching category, now deal with the message
set account of frontWindow to defaultAccount
return -- job finished, quit the script
end if -- not in this contact
end repeat -- try next found contact
-- not in the contacts for that address, try next one
end repeat
-- finished all the recipients - no match found, end the script
end tell
end run

on checkDefaultAccount()
-- check to see if a defined defaultAccount has been deleted
tell application "Microsoft Entourage"
try
get defaultAccount
on error --- no such account
set defaultAccount to missing value
end try

-- now check to see if there is an account set up
if defaultAccount = missing value then
-- No account set up
set thenames to {}
repeat with aName in (name of every POP account)
copy aName & " (POP) " to end of thenames
end repeat
repeat with aName in (name of every IMAP account)
copy aName & " (IMAP)" to end of thenames
end repeat
try
set theAccount to item 1 of (choose from list thenames with
prompt "Select the account for the messages:" OK button name "Select"
without multiple selections allowed and empty selection allowed)
on error
-- user cancelled
return -99
end try
if theAccount ends with " (POP) " then
set defaultAccount to POP account (text 1 thru -8 of
theAccount)
else
set defaultAccount to IMAP account (text 1 thru -8 of
theAccount)
end if

end if
end tell
return 0
end checkDefaultAccount


on checkRecipientCategory()
-- check to see if a defined recipientCategory has been deleted
tell application "Microsoft Entourage"
try
get recipientCategory
on error --- no such category
set recipientCategory to missing value
end try

-- Now check to see if a category has been set up
if recipientCategory is missing value then
set theCats to name of every category
try
set recipientCategory to category (item 1 of (choose from
list theCats with prompt "Select the Category for recipient of messages to
be processed:" OK button name "Select" without multiple selections allowed
and empty selection allowed))
on error
-- user cancelled
return -99
end try
end if
end tell
return 0
end checkRecipientCategory
 
D

Daiya Mitchell

Say, a script that triggers on Send, and if the address meets a particular
I have a script that runs once a minute and checks the frontmost window. If
it is a draft message window it will check the category of the recipients,
and set the account of the message appropriately.
<snip>

Bless you, Barry, this has been driving me mad. I will check it out and post
back if any problems.

Daiya
 
B

Barry Wainwright

<snip>

Bless you, Barry, this has been driving me mad. I will check it out and post
back if any problems.

Daiya


Thanks :)

For anyone else interested, I have uploaded this script, with full
instructions, to scriptbuilders.net - it should be appearing there shortly.
The script is called 'Set Account by Category'.
 
D

Daiya Mitchell

Paul's appears to work on outgoing mail, Barry's works on messages in
progress.

Sadly, I knew Other Account X existed but had a very positive and completely
confused idea of what it did.
 
B

Barry Wainwright

They both work in a similar way, on the draft message window, but Paul's is
an old, old script who's origins pre-date Entourage and it's wonderful
categories. Mine was written about two years ago and was able to take
advantage of the categories. To differentiate between the accounts Paul's
script uses address book groups. Mine uses categories. Two different
approaches to the same end - use whichever of them suits your purposes the
best. I am sure that neither of us will take offence at the other :)
 
P

Paul Berkowitz

Paul, How does this new script, Set Account by Category, differ from your
Other Account X script?

It's basically the same idea (and I think Barry may have borrowed the idea).
But I first created Other Account script way back for Outlook Express - in
fact it was my very first released script. OE did not have categories - so I
used groups. It still works fine in its present incarnation for Entourage X
and 2004.

But it's more bother to add a contact to a group than to assign it a
category. And most of us tend to use categories a lot more for filtering
contacts like this - group are really just meant for sending an email to
lots of people at once, and also useful when you don't want to make them all
contacts - which is not applicable here. But the main thing is adding a
person to a group means going to the address book, finding the group,
opening it, finding the contact, dragging the contact to the group. It's
easier just to right-click on the contact and assign the category.

--
Paul Berkowitz
MVP MacOffice
Entourage FAQ Page: <http://www.entourage.mvps.org/faq/index.html>
AppleScripts for Entourage: <http://macscripter.net/scriptbuilders/>

Please "Reply To Newsgroup" to reply to this message. Emails will be
ignored.

PLEASE always state which version of Microsoft Office you are using -
**2004**, X or 2001. It's often impossible to answer your questions
otherwise.
 
B

Barry Wainwright

It's basically the same idea (and I think Barry may have borrowed the idea).

Nah - just re-invented it when I needed the same functionality.

I have a bad habit of not seeing what is already available and just going in
and re-inventing the wheel every once in a while.
 
Top