Applescript: reorder mail rules
Hi Community,
I can't find the syntax for reordering existing mail rules using applescript anywhere on the web. If someone could just post an example of how to do this that would be awesome. Thanks!
Hi Community,
I can't find the syntax for reordering existing mail rules using applescript anywhere on the web. If someone could just post an example of how to do this that would be awesome. Thanks!
So the order of the rules does matter.
Yes, the order matters in Mail, but the order pulled by getting the rules may not be changeable except by deleting all of them and inserting them via AppleScript in the order you wish.
And, as I already stated, if you don’t see it in the Library, there isn’t a command to do it (whatever the “it” is).
I tried to get the list of rules and edit it, but it did not take. You would have to extract each rule and store that copy so you could rebuild the list through inserting the copy into the list.
Open the Mail library in Script Editor. That will tell you everything you can do with Mail using AppleScript.
There isn't an order to rules except maybe inserting them into the application in the order you wish.
If the position in the list matters to Mail, then you could insert your rules into the list of rules where you want it.
My quick attempt at using that method did nothing.
According to https://support.apple.com/guide/mail/use-rules-to-manage-emails-you-receive-mlhlp1017/mac "If you have multiple rules, they’re applied in the order in which they appear in the list of rules; drag a rule up or down to change the order."
So the order of the rules does matter.
And it appears that you're correct when creating a rule. The following applescript syntax can be used:
set newRule to make new rule at end of rules with properties {name:"Woohoo rule", forward message:"camelot@mac.com"}
Notice the "at end of rules" syntax. This implies (at least during the creating of a rule) that it's location in the list of rules can be set. Not exactly sure what the syntax would be to put it in a specific location. Any thoughts on that within the above code?
You don't always want the set the new rule at the bottom of the list. As Barney-15E mentioned they are acted upon in the order they are in. Also, rules only work on emails in the Inbox. So if a rule moves an email to another mailbox subsequent rules will not affect them.
Applescript: reorder mail rules