I was never able to resolve creating a satisfactory rule directly, so resorted to the GUI.
on mailRuleCreator:sender
# say 503
set isThisStartUp to false # sender as text is "StartUp"
tell application "Mail"
activate
try
do shell script ("sleep 0.2")
tell application "System Events" to tell process "Mail"
click menu item "Message Viewer" of menu 1 of menu bar item "Window" of menu bar 1
end tell
if not (exists mailbox "* items to shift") then make new mailbox with properties {name:"* items to shift"}
set theAddRuleMailbox to false
if not (exists rule "Move to '* items to shift'") or not isThisStartUp then
set inBoxList to name of every account whose enabled is true as list
if (count of inBoxList) = 1 then
set theAddRuleMailbox to item 1 of inBoxList
else
set theAddRuleMailbox to choose from list inBoxList with prompt "Please choose an Account to which to add the Mail rule " & return & return & "\"Move to '* items to shift'\"." & return with title "Mail Manager add Mail rule" OK button name "Choose this Inbox Account" cancel button name "I'll set the rule myself"
end if
end if
if theAddRuleMailbox ≠ false then
try
delete (every rule where name contains "items to shift")
end try
try
delete (every rule where name contains "Autom")
end try
if not (exists rule "Move to '* items to shift'") then
tell application "System Events" to tell process "Mail"
try
keystroke return
end try
click menu item "Preferences…" of menu 1 of menu bar item "Mail" of menu bar 1
do shell script ("sleep 0.1")
click button 8 of toolbar 1 of window 1
#
# Set descriptive name of rule
#
click button "Add Rule" of group 1 of group 1 of window "Rules"
set value of text field 1 of sheet 1 of window "Rules" to "Move to '* items to shift'"
#
# First, select the 'all' menu item
#
click pop up button 1 of sheet 1 of window "Rules"
click menu item "all" of menu 1 of pop up button 1 of sheet 1 of window "Rules"
#
# Set first scroll area, 'Conditions'
#
click pop up button 1 of scroll area 1 of sheet 1 of window "Rules"
# The darn popups change numbers whilst 'Account' is being selected
try
click menu item "Account" of menu 1 of pop up button 1 of scroll area 1 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
end try
# so we have to try both 1 & 2 popups
try
click menu item "Account" of menu 1 of pop up button 2 of scroll area 1 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
end try
click pop up button 1 of scroll area 1 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
click menu item (theAddRuleMailbox as text) of menu 1 of pop up button 1 of scroll area 1 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
#
click button "add criterion" of scroll area 1 of sheet 1 of window "Rules"
#
click pop up button 3 of scroll area 1 of sheet 1 of window "Rules"
click menu item "Every Message" of menu 1 of pop up button 3 of scroll area 1 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
#
# Set second scroll area, 'Actions'
#
click pop up button 1 of scroll area 2 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
click menu item "Move Message" of menu 1 of pop up button 1 of scroll area 2 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
click pop up button 2 of scroll area 2 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
click menu item "* items to shift" of menu 1 of pop up button 2 of scroll area 2 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
#
click button "add action" of scroll area 2 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
#
click pop up button 3 of scroll area 2 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
click menu item "Run Applescript" of menu 1 of pop up button 3 of scroll area 2 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
click pop up button 4 of scroll area 2 of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
try
click menu item "Mail Manager Caller" of menu 1 of pop up button 4 of scroll area 2 of sheet 1 of window "Rules"
on error
try
click menu item 1 of menu 1 of pop up button 4 of scroll area 2 of sheet 1 of window "Rules"
end try
end try
do shell script ("sleep 0.1")
click button "OK" of sheet 1 of window "Rules"
do shell script ("sleep 0.1")
try
click button "Don’t Apply" of sheet 1 of window "Rules"
on error
keystroke return
end try
do shell script ("sleep 0.1")
try
click button 1 of window 1
end try
end tell
end if
end if
on error errmsg number errNum
tell application "System Events" to tell process "Mail"
try
do shell script ("sleep 0.1")
click button "OK" of sheet 1 of window "Rules"
end try
try
click button 1 of window 1
end try
end tell
display dialog "mailRuleCreator error " & errmsg
end try
end tell
end mailRuleCreator: