Creating a Filter Rule in Mail with AS

Working on how to add new rules to Mail.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Mail"
	set newRule to make new rule at end of rules with properties {name:"Test rule", forward message:""}
	tell its rule newRule
		make rule condition with properties {rule type:(any recipient), qualifier:does contain value}
	end tell
end tell

and it throws this error (see attached screenshot)
I don’t see why there is an error “Can’t make rule into a type <>” (see attached screenshot)

Don’t understand the “Error counting rule conditions” either.( I haven’t figured out how to upload a debug report here except by screenshots)

Pointers very welcome.

MacOS Big Sur
Mac mini M1
SD: v 8.0.1 (8A36)

Hey Dan,

This works for me on Sierra through Mojave.


# Auth: Christopher Stone
# dCre: 2015/10/01 09:04
# dMod: 2021/07/15 14:05
# Appl: Mail, System Events
# Task: Add items to Promotions Rule
# Libs: ELb
# Osax: None
# Tags: @Applescript, @Script, @Mail, @System_Events, @Add, @Email, @Address, @Promotions, @Rule
# Note: 2017/02/16 17:55 - updated UI-Scripting for Sierra

set ruleName to "Promotions - IN"

tell application "Mail"
   set msgSelList to selection
   if length of msgSelList = 1 then
      set mailRule to rule ruleName
      if mailRule exists then
         set theMsg to item 1 of msgSelList
         set msgSenderAddress to (sender of theMsg)
         set msgSenderAddress to text returned of (display dialog "Confirm Email Address For Subscriptions Filter…" buttons {"Cancel", "OK"} default button "OK" default answer msgSenderAddress)
         tell mailRule
            make new rule condition at end of rule conditions with properties ¬
               {rule type:from header, qualifier:does contain value, expression:msgSenderAddress}
         end tell
         error "The named Mail-Rule does not exist!"
      end if
      error "Problem with message selection!"
   end if
end tell