In Apple Mail I use a mail rule to trigger an Applescript for one specific sender. This script for the moment just logs the subject of the mail message. The script looks like this:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
set cnt to 0
repeat with msg in theMessages
try
set txt to subject of msg
my logToConsole(txt)
on error err
my logToConsole("Error processing message: " & err)
end try
end repeat
end perform mail action with messages
end using terms from
on logToConsole(txt)
do shell script "/usr/bin/logger -t \"Mail script:\" " & txt's quoted form
end logToConsole
When a new message from the specified sender comes in, the script is triggered aand writes the subject to the console. So far so good.
However, the subject written to the console is the subject of the last message in the Inbox straight under the new message, not the subject of new message.
To illustrate this, lets say, my Inbox looks at the beginning like this:
[format]
From To Subject Date
Maria Leo Overview Today 6:03pm
Carl Leo Meeting Today 5:13pm
…
[/format]
Then the new message (from Peter) arrives:
[format]
From To Subject Date
Peter Leo Details Today 8:45pm
Maria Leo Overview Today 6:03pm
Carl Leo Meeting Today 5:13pm
…
[/format]
Peter is the sender I used in the Applescript mail rule, so the script is triggered on arrival, but it logs to the console the string “Overview”, not the string “Details”.
Is there a way to fix this? I obviously want to work on the new message.