Hi, I want to open an email message with AppleScript. Everything is working correctly, but in the Mail app, instead of focusing on targetMessage, it highlights the email after the target message.
When I use:
tell targetMessage to open
the correct email opens in new window but the wrong email is highlighted in the Mail app list.
tell application "Mail"
activate
set targetAccount to missing value
repeat with anAccount in every account
if name of anAccount is "AccountName" then
set targetAccount to anAccount
exit repeat
end if
end repeat
if targetAccount is not missing value then
set targetBox to missing value
repeat with aBox in mailboxes of targetAccount
if name of aBox is "MailboxName" then
set targetBox to aBox
exit repeat
end if
end repeat
if targetBox is not missing value then
set targetMessage to missing value
set oneWeekAgo to (current date) - (7 * days)
set filteredMessages to (every message of targetBox whose date received ≥ oneWeekAgo)
repeat with aMessage in filteredMessages
try
if message id of aMessage is "MessageID" then
set targetMessage to aMessage
exit repeat
end if
end try
end repeat
if targetMessage is not missing value then
if (count of message viewers) > 0 then
set mailViewer to message viewer 1
else
set mailViewer to make new message viewer
end if
tell mailViewer
set selected mailboxes to {targetBox}
delay 0.2
set selected messages to {targetMessage}
end tell
return "Found"
else
return "Message Not found"
end if
else
return "Folder Not found"
end if
else
return "Account Not found"
end if
end tell
Why is this behavior happening?