Hey, everyone. I’m stuck with an intensely annoying issue: I have an AppleScript that’s attached to a Mail rule. The intended behavior is for the rule to check the message for a csv-formatted attachment and, if one exists, save it and run some other processes on it. Unfortunately, I’m getting stymied right at the beginning: it only works if I right-click a message and select “Apply Rules.” I suspect the issue is that when the rule runs, the message isn’t actually selected, so the script isn’t able to process it.
Here’s the relevant portion of the script:
using terms from application "Mail"
on perform mail action with messages theMessages for rule theRule
-- Get incoming messages that match the rule
tell application "Mail"
repeat with theMessage in theMessages
-- Save the attachment
repeat with theAttachment in theMessage's mail attachments
set filename to name of theAttachment as string
if (characters -1 thru -3 of filename) as string = "csv" then
set asPath to (asFolder & ":" & filename) as string
save theAttachment in file asPath
--remainder of code omitted for brevity
--all “end”s are in place
Again, I believe the problem is that when the message comes in, Mail doesn’t select it. Since there’s no selection, the script is unable to get its attachment. How do I tell Mail to select the message when it comes in, so it can grab the attachment if needed?
Thanks so much! :-)