Title: Re: Sort recipients in draft message window
On or near 3/9/04 7:39 AM, Remo Del Bello at [EMAIL PROTECTED] observed:
> I seem to recall a script being posted or being announced on the list that
> sorted the recipient list in a draft message window. Anyone know where I
> could find it?
>
I've not seen such a script (there was one to sort members of a group). How would you want them sorted: by e-mail address, by last name, or by entire name? (Last name could be problematic, since recipient names are a single field. The usual way would be to assume the last word is the last name, or the first word is the first name, but this would get incorrect results with "Dick Van Dyke" or "John Paul Smith".)
If you care to try it yourself, here is a sort routine:
(* Examples of using sortList
set theList to {1, 3, 0, 4, 2, 8, 7, 2, 4, 8, 5}
My sortList (thelist, “Ascending”)
set thelist to {"d", "a", "v", "i", "d"}
my sortList (thelist, “Descending”)
set thelist to {"bat", "cat", "apple"}
Set newlist to my sortList(theList, "Descending")
*)
-- Call with second parameter = "Descending" or "Ascending"
on sortList(l, direction)
set testClass to class of item 1 of l
repeat with j from 1 to count l
if class of (item j of l) is not testClass then
display dialog "Cannot sort lists of mixed class."
error 128
end if
end repeat
if length of l ≤ 1 then return l
set x to item 1 of l
set ll to rest of l
set l1 to {}
set l2 to {}
repeat with i in ll
if direction = "Descending" then
if x > i then
set l2 to l2 & i
else
set l1 to l1 & i
end if
else
if x < i then
set l2 to l2 & i
else
set l1 to l1 & i
end if
end if
end repeat
if length of l1 > 1 then set l1 to sortList(l1, direction)
if length of l2 > 1 then set l2 to sortList(l2, direction)
return l1 & x & l2
end sortList
Paul’s message about assigning recipients would be useful, too:
On 14/12/01 9:27 pm, "Domains4Days.com" <[EMAIL PROTECTED]> wrote:
> For incoming mail : I can't seem to find the command to get the "to:" field
> in a message.... (to put on the clipboard)
>
> tell application "Microsoft Entourage"
> set theMessage to the displayed message of the front window
>
> set theSender to sender of theMessage
>
> set towho to ???account/or/recipient??? of theMessage
>
> set the clipboard to theSender & "-" & towho
>
> end tell
First place to look is in the Entourage Applescript Dictionary. Get this by
choosing the menu item 'open dictionary' if you're using Apple's Script
Editor or Smile.
This shows that an 'incoming Message' is defined as having an element called
'recipient' which can be got by index (first recipient, recipient 2, etc) or
by test (recipients whose x is y).
> Class incoming message : (inherits from message) An incoming e-mail message
> Plural form:
> incoming messages
> Elements:
> attachment by numeric index, test
> recipient by numeric index, test
Now, look further on in the dictionary and see how a recipient is defined.
It says this:
> Class recipient : Message recipient
> Plural form:
> recipients
> Properties:
> address address -- the recipient's address
> recipient type to recipient/cc recipient/bcc recipient/newsgroup recipient
> -- the type of recipient
So, it has two properties – an address (of type ‘address’, so we need to
look back at the disctionary again), and the ‘recipient type’ .
Now, tie this in with the ‘recipient by test’ of the Incoming Message class
and we start to get somewhere:
> recipients of theMess whose recipient type is to recipient
> -- {recipient 1 of incoming message id 29730}
Note that the value returned is a list! This is because there could be more
than one ‘to recipient’!
Now, remember what we said about the addresses? We need to look back into
the dictionary to see how the ‘address’ class is defined:
> Class address : An e-mail message address
> Plural form:
> addresses
> Properties:
> display name Unicode text -- the name used for display
> address string -- the e-mail address
Here it can get a little confusing. CLASS address has a property called
‘address’ that is of type string. The authors of Entourage could possibly
have chosen a better phrase here to make thingsd a little clearer (“address
string” or “email address”?), but still, we have to work with what we’ve
got.
Now,’recipients of theMess whose recipient type is to recipient’ got us a
reference to a list of recipients ({recipient 1 of incoming message id
29730}). We can ask for their addresses, which will get us the entire
record:
> address of (recipients of theMess whose recipient type is to recipient)
> -- {{address:"[EMAIL PROTECTED]", display name:"Entourage
> mac Talk"}}
Or, you can ask for the bit you want:
> address of address of (recipients of theMess whose recipient type is to
> recipient)
> -- {"[EMAIL PROTECTED]"}
>
> Display name of address of (recipients of theMess whose recipient type is to
> recipient)
> -- {"Entourage mac Talk"}
This is the information you were after! Remember that it is still in list
form and there could be more than one. There could also be less than one!
(messages without a ‘to’ recipient are valid!), so some testing will prevent
a script error when you try to get properties of recipients that are not
present.
I hope this helps you get the information you wanted for your script and
also to learn how to interpret the AS dictionaries. Digging in the
dictionary can be the best way to learn just what can be done in an
application. That of course, relies on the dictionary being well written.
Fortunately, with just one or two small exceptions, the Entourage dictionary
is one of the best in existence, and is well worth perusing.
HTH!
--
Barry Wainwright
<http://www.barryw.net>
When choosing between two evils, I like to
choose the one I've never done before.
- Sort recipients in draft message window Remo Del Bello
- Transferring from Shell iBook VKN
- Re: Transferring from Shell iBook Diane Ross
- Allen Watson
