2
  • I've created some rules in my Mail.app to change background color of specific messages
  • And also I've created rules in the mail server to move specific messages to some folder

For messages in the Inbox folder everything is fine.

But if message has been moved by server rule into another folder, then rules in the Mail.app do not apply (and for some twisted reasons this is by design: https://support.apple.com/kb/PH19162?locale=en_US&viewlocale=en_US).

And if I apply rules manually by hitting Command + Option + L, then Mail.app rules will apply as they should.

I want to automate this action. Is it possible to achieve with Apple Script? Can you help me with it? The steps should be as follows, I guess:

  1. Choose Smart Folder "today";
  2. Select all messages in this folder;
  3. Perform the action "Apply Rules" for selection.
using terms from application "Mail"
        tell application "Mail"
            set the message_count to the count of HOW-TO-GET-MESSAGES-FOR-TODAY-SMARTBOX
            repeat with i from 1 to the message_count
                set this_message to item i of MESSAGES-FROM-TODAY-SMARTBOX

                tell this_message

                -- here goes something like APPLY RULES

                end tell

            end repeat
        end tell
end using terms from

Edit 1.

If it's not possible for Smart Folder, then I want to do it will all the messages in all mailboxes (or with messages in specific mailbox (or just for any new message regardless of folder)).

  • It's my understanding you cannot reference the smart mailboxes through AppleScript in that manner as they are not actually objects. If you try to find the word "smart" in the Mail AppleScript Dictionary it doesn't exist. All info re: mailboxes in the AppleScript Dictionary do not reference "Smart Mailboxes". If you run tell application "Mail" to get mailboxes you'll not see any "Smart Mailboxes" in the output. Additionally at the filesystem level there are no <smart_mailbox_name>.mbox files like there is for actual mailboxes. You're going to have to take a different approach, if possible. – user3439894 May 18 '16 at 23:41
  • @user3439894 well ok, not a problem, then I want to do it with all the messages. – retif May 19 '16 at 5:53
  • Apply the AppleScript to all messages is insane, it will take forever. – ePi272314 Nov 13 '17 at 2:27
  • In the mean while I discovered another problem. Rules doesn't work if you apply them by hand (Command+Option+L) to the messages in a smart mailbox. – ePi272314 Nov 13 '17 at 2:28
  • I think you must change the approach. Is it really important for you that the rules in the mail server move the message to different folders? If what you want is to skip the Inbox at first, you could set your server rules to move all those messages to the same folder. Later would be easily run an AppleSript on that folder to: apply the background colors and move the message to the final destination. – ePi272314 Nov 13 '17 at 2:39

You must log in to answer this question.

Browse other questions tagged .