I have to say, every time I have tried to use Mail Rules and Mail Rule Actions using AppleScript, I have regretted it. Seems like every new OS has a new bug with Mail Rules, and I wait and wait, hoping it is fixed. By that time there is another problem which makes it dysfunctional. Today is no exception.
Here is a script I want to use, based on a script Mark A posted here recently. I wanted to use it in a Mail Rule to move attachments into a specific folder when the message had a certain Subject. (Note on my Mac, using POSIX file to save the attachment did not work, which I mentioned in his previous post)
using terms from application "Mail" on perform mail action with messages passedMessages for rule theRule set desktopPath to (path to desktop) -- Get incoming messages that match the rule tell application "Mail" repeat with aMessage in passedMessages set attachmentList to (every mail attachment of aMessage) --the line above chokes and error msg is "osascript got an error: Can’t get every mail attachment of message id 90245 of mailbox "INBOX" of account id "A5369D37-E8CD-42D4-90CD-B1AE39D530F6". repeat with anAttachment in attachmentList set attachmentName to name of anAttachment save anAttachment in file (desktopPath & attachmentName) -- Mark's original script here used POSIX file, but that did not work on High Sierra on my Mac end repeat end repeat end tell end perform mail action with messages end using terms from
With various incarnations and rearrangements, sometimes I would get the error that Mail doesn’t understand ‘count’ in regard to mail attachments. But it still choked on the same line.
What seems to be causing the problem is the term ‘message id 90425’ from what some experimentation below revealed:
(* tell application "Mail" set tlist to every mail attachment of message id 90245 of mailbox "INBOX" of account id "A5369D37-E8CD-42D4-90CD-B1AE39D530F6" end tell -- this won't compile --Error message is "Expected end of line but found number" and '90245' is highlighted --mail rule passes this when the rule catches a message which matches the rule: -- message id 90245 of mailbox "INBOX" of account id "A5369D37-E8CD-42D4-90CD-B1AE39D530F6" --this won't compile either: tell application "Mail.app" subject of message id 90245 of mailbox "INBOX" of account id "A5369D37-E8CD-42D4-90CD-B1AE39D530F6" end tell *) tell application "Mail" set tlist to every mail attachment of message 2 of mailbox "INBOX" of account id "A5369D37-E8CD-42D4-90CD-B1AE39D530F6" end tell -- this is 'copy reference' for the selected message which has a caution icon in Explorer...it uses Message 2 -- to get the descriptor for the selected message which uses the message id. --if Mail passes the message id which does not seem to work in script, what's the workaround??? tell application "Mail" tell its account "iCloud" tell its mailbox "INBOX" message 2 end tell end tell end tell
OS X 10.13.6
Mail Version 11.5 (3445.9.1)
So, anyone got any thoughts?
Thanks in advance