Hi All,
I found a very weird bug when using an AppleScript trigger for a Mail.app rule:
If the script inside “~/Library/Application\ Scripts/com.apple.mail/” is a symlink to an .scpt file
when an email is received, the rule script is not applied to the latest email, but to the one before it.
However if I select a message, right-click and “Apply Rules”, then the rule is applied to the right email.
Also, if I replace the symlink by a hard copy, the behavior is back to normal.
Anyone has an idea of where this comes from, if this is fixable, or where I should report that?
Thanks,
Aurel
More context
I am defining an AppleScript to be triggered on “Every Message” rule (I haven’t tried with a different type of rule though).
Here is a demo script to reproduce my issue :
using terms from application "Mail"
-- Function applied to each mail when rule is triggered
on perform mail action with messages theMessages for rule theRule
try
parseMessages(theMessages)
on error errMsg number errNum
display dialog "Error: " & errMsg & " (Code: " & errNum & ")" buttons {"OK"} default button 1 with icon caution
end try
end perform mail action with messages
on parseMessages(theMessages)
-- Prompt user when more then 3 messages are selected
set messagesCount to (count of theMessages)
if messagesCount > 3 then if button returned of (display alert "Apply rule to " & messagesCount & " messages?" as critical buttons {"Apply", "Cancel"} default button 2) is "Cancel" then return
-- Display message information
repeat with msg in theMessages
display dialog "Title: " & subject of msg as string
end repeat
end parseMessages
end using terms from
As this script is part of a global project:
The source is located in ~/projects/email_parsing/
If I run the following and use “mac_mail_rule_demo” the rule is not applied to incoming messages but to the last one arrived before.
ln -s ~/projects/email_parsing/mac_mail_rule_demo.scpt ~/Library/Application\ Scripts/com.apple.mail/
If I run the following then the behavior is back to normal:
cp -f ~/projects/email_parsing/mac_mail_rule_demo.scpt ~/Library/Application\ Scripts/com.apple.mail/
I am on M4 pro, macOS Tahoe Version 26.5.1 (25F80)
Mail.app Version 16.0 (3864.600.51.1.1)
Also, my mailbox account is an IMAP Microsoft Exchange one