On Jan 1, 2011, at 9:51 PM, Christopher Stone wrote:
Keep in mind that 'message viewer 1' does not refer the the front message viewer. If you have more than one open you can get into trouble using that syntax. (Mail continues to be an ugly beast to script.)
But ...
does seem to work correctly. I have a very large script that depends on this.
I have simplified the applicable part of my script to get this ...
on run
try
my main()
on error errText number errNr
if errNr = -128 then
return
else if errNr = -2700 then
tell application "Mail" to display dialog errText buttons {"OK"} default button 1
else
"Error = " & errNr & return & errText
display dialog the result buttons {"OK"} default button 1
end if
end try
end run -------------------------------------------------------
on main()
tell application "System Events" to ((name of every process) contains "Mail")
if not the result then
beep
return
end if
tell application "Mail"
activate
try
set frontViewer to (some message viewer whose index is 1)
on error
error "A message viewer window must be open and frontmost in Mail."
end try
set mailBoxList to (selected mailboxes of frontViewer)
display dialog (name of (item 1 of mailBoxList)) as text buttons {"OK"} default button 1
end tell
end main -------------------------------------------------------
I have tried running it with various and multiple windows open in Mail and it behaves correctly every time.
I can't break it. Can you?