Re: Mail question, another way
Re: Mail question, another way
- Subject: Re: Mail question, another way
- From: John Delacour <email@hidden>
- Date: Fri, 1 Aug 2003 15:40:02 +0100
- Mac-eudora-version: 6.0a29
At 9:02 pm -0700 31/7/03, Christian Boyce wrote:
Judging by the responses I got (or didn't) I must have phrased my
question about scripting Apple's Mail program rather poorly. I'm
going to try again.
You are making the rather optimistic assumption that Mail is
scriptable in any sane sense of the word.
What I really want is to keep the message window open, and (somehow)
move to the next message *in the same window.* I don't want to close
the message window, and then double-click the next message. I just
want to fill the message window with the next (or previous) message.
So far as Mail's aete is concerned, the window does not have a
message either as element or property and the message does not have a
window ditto, so there's the beginning of you problem.
I might be able to do it if I could figure out the basic syntax for
referring to the current message (the one that is frontmost). I have
tried things like
tell application "Mail"
set x to the id of current message
end tell
but it doesn't compile.
Any hints?
The only way you can guess which message is in the front window is by
assuming that the message is highlighted somewhere else. Let's
assume that since you have just double-clicked it, it's highlighted
in a message viewer just behind
Here's how to refer to it:
tell application "Mail"
set _message to item 1 of (get selected messages in the front message viewer)
--> message 3 of mailbox "INBOX" of account "email@hidden" of
application "Mail"
end
Elegant, isn't it?! So much more expressive than boring old "front message".
So it's just possible that you might now like to open _message with
an Apple Event. Just in case the thought had never occurred to you
(as it has obviously not occurred to Mail's scripting team) this
would be done in Eudora by writing
open _message
open message ""
Forget it. You can't open it. But of course you know that it's
message 3 in the mailbox, so at least you can say, Well the next one
will be message 4, so all I need to do is get the index of this
message and then refer to the next one by index. Tough! The message
has no index property and no id property.
Now suppose you are cavalier enough to have TWO message viewers open
and a message selected in each of them and have the temerity to tell
Mail to 'get the selection'. You'll get an answer but it won't give
you a list of the selected messages. To get that (or rather a list
of lists) you need to use a different term 'selected messages' which
applied only to message viewers.
tell application "Mail" to get selected messages in message viewers
I said you can't get the index of a message because it has no such
property, but you can get its index if you loop through all the
messages visible in the message viewer, provided you're keeping
things simple and displaying messages from a unique mailbox in that
viewer. Otherwise things will get very complicated. Here is a
script that will _select_ (and display in the preview window if
you're using that) the next message by index number. This works here
but I can't guarantee it will work for you because I'm using a later
version of the app, which is no better but just bad in newer places.
tell application "Mail"
try
tell the front message viewer
set _mlist to visible messages
set _message to item 1 of (get selected messages)
set _mbox to mailbox of _message
repeat with i from 1 to count _mlist
if _message is message i of _mbox then exit repeat
end repeat
set selected messages to {message (i + 1) of _mbox}
end tell
end try
end tell
Now if a message is selected and you press the <enter> or return key,
it will open in a window, so you could combine the above with a GUI
event to 'key stroke return' and another event to close the previous
window if its title is the same as the selected message's subject ...
or whatever.
At least all this has the merit of being possible and a good exercise
in beating the system, but many scripting things in Mail are simply
not possible and the rest require such absurd scripting techniques
that the game is hardly worth the candle.
I have believed for a long time that the whole Mail dictionary ought
to be scrapped and a new team employed to write a new one from
scratch. Until this is done I see no hope of its ever being anything
but an insult to the scripting community.
JD
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.