• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Make New Rule Condition with AppleScript and Access it Via System Events
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Make New Rule Condition with AppleScript and Access it Via System Events


  • Subject: Make New Rule Condition with AppleScript and Access it Via System Events
  • From: Christopher Stone <email@hidden>
  • Date: Fri, 25 Sep 2015 19:49:48 -0500

Hey Folks,

So, I managed to create a new rule-condition in Yosemite's Mail.

It's difficult to encompass all the possible settings in the script, so I decided to open the rule-editor and access the new condition directly to confirm its creation and make any desired adjustments.

I know the location of this rule already – it's rule number 1.

It is possible to get to the correct row in the rule-editor table by using the rule's name, but with over 50 rule-conditons it takes an inordinate amount of time — so I'm sticking with a positional descriptor.

This script is decently fast and much easier than manually going to the rule-condition.

--
Best Regards,
Chris

-------------------------------------------------------------------------------------------
# Create New Rule-Condition in Existing Rule
-------------------------------------------------------------------------------------------

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 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

-------------------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Apple Mail "Smart Mailboxes" and Rules...
  • Next by Date: Re: tags manipulation
  • Previous by thread: Re: Yosemite Mail - Creating a Rule - Failure
  • Next by thread: Where is Trash Folder(?)?
  • Index(es):
    • Date
    • Thread