-------------------------------------------------------------------------------------------
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 msgFromAddress to (sender of theMsg)
tell mailRule
make new rule condition at end of rule conditions with properties ¬
{rule type:from header, qualifier:does contain value, _expression_:msgFromAddress}
end tell
else
error "The named Mail-Rule does not exist!"
end if
else
error "Problem with message selection!"
end if
end tell
-------------------------------------------------------------------------------------------
# Use System Events to Quickly Access the New Rule-Condition.
-------------------------------------------------------------------------------------------
tell application "System Events"
tell application process "Mail"
set frontmost to true
click menu item "Preferences…" of menu 1 of menu bar item "Mail" of menu bar 1
tell front window
if its name is not "Rules" then tell toolbar 1 to click button "Rules"
if {position, size} ≠ {{583, 23}, {663, 1173}} then
set {position, size} to {{583, 23}, {663, 1173}}
end if
tell tab group 1 of group 1 of group 1
set selected of row 1 of table 1 of scroll area 1 to true
click button "Edit"
end tell
tell text field 1 of scroll area 1 of sheet 1
set focused to true
end tell
end tell
end tell
end tell
-------------------------------------------------------------------------------------------