[strike]This is driving me nuts because I’m sure there’s got to be a fairly simple answer (last time I said that, Nigel posted a 322 line answer … I really shouldn’t tempt fate again!).[strike]
How do I determine the type of window that’s frontmost in Mail.app - I want to know if it’s an incoming message (message viewer or a single message in a window), an outgoing message, or something else (eg preferences pane, activity window, etc.). If it’s an incoming/outgoing message I’d like to know the sender and recipient and if it’s an incoming message I’d like to know which mailbox it’s in also.
I thought this almost worked:
tell application "Mail"
if (index of front message viewer is 1) then
try
set senders to ""
set messList to selected messages of front message viewer
repeat with thisEmail in messList
set senders to sender of thisEmail & ";" & senders
end repeat
return "incoming: " & senders
on error
return "incoming"
end try
else
return "outgoing"
end if
end tell
But it turns out that “message viewer” only refers to the main Mail.app window and if you view a single message (eg by double-clicking in the message list) it isn’t a “message viewer” so the code fails annoyingly.
It’s also incomplete in not determining the details of an outgoing message or distinguishin between outgoing messages and prefpanes or determining mailbox for a message being read.
I am not having a Good Coding Day today!
r
PS
I’m using Leopard, 10.5.1 - the Operating System possibilities in the System Info section need updating