Apple Mail – Add Email Address to Rules

I have an Apple Mail rule titled 'Delete' which automatically deletes email I do not wish to receive which email does not allow for unsubscribing. I want to use KM to add the current on screen email to that list and select 'Apply'. I am having difficulity selecting the Delete rule for editing. The keystrokes required are Mail >Preferernces >Rules >Delete >Edit >(select topmost circled +) >OK >Apply. I can get to Mail > Preferences >Rules, but I cannot seem to get the specific rule (Delete) to select so that It can be edited. Please help...

Thanx

I think rules in Mail can be created/edited with AppleScript.

Which element(s) of the current on-screen mail do you want to add as condition?
(Sender? Sender domain? Subject? …)

Here an example:

This will add the sender(s) of the selected message(s) as new condition(s) to your existing “Delete” rule:

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

set theProperties to {}

tell application id "com.apple.mail" -- Mail.app
  set theMessages to the selection
  repeat with i in theMessages
    set the end of theProperties to sender of i
  end repeat
  tell rule "Delete"
    repeat with i in theProperties
      make rule condition at end of rule conditions with properties {rule type:from header, qualifier:does contain value, expression:i}
    end repeat
  end tell
end tell

[demo] Add Conditions to Existing Mail Rule “Delete”.kmmacros (2.5 KB)

  1. Download and import the macro from the above link.
  2. Make sure the macro and the macro group are activated.
  3. In Mail select one or more messages.
  4. Run the macro (default trigger: ⌃⌥⌘F1).
  5. Check your “Delete” rule: the senders of the selected messages should have been added there as new conditions.
1 Like

Sender

If Sender, then the demo macro from above should fit. Give it a try, we can always modify it.

Sorry Tom… Guess I just don’t understand. I have followed your instructions. Download >activated >select email message >enter the trigger… at this point all I get is a single 'ding' (bell). I just don’t get it. The macro is there in KM and it is activated… but it just rings. I have tried several times and ways. I always just get a bell… a single 'ping'. You have any more ideas?

Oops… OK I found the reason for the ding… Already had that trigger in use.

Regardless, I changed the trigger and the script does not add the sender to the Delete rule… Please know that when I add manually there is a maybe a five second delay after clicking 'Edit' because my delete list is rather long. Could that be a problem?

No. I just tested this:

  1. With the script I added ~400 senders to my “Delete” rule
    • Now opening the rule in Apple Mail for editing takes about 10 seconds
  2. With the script I added 3 more senders
    • Script worked fine and fast, the 3 senders have been added at the end of the existing 400 senders

Try to enable the script output to a window, and see if there are any errors or hints:


The output you should get, if the script works fine, is something like this:

29-pty-fs8

(This is the index of the last condition added.)

OK, got it… The error was "Not authorized to send apple events to mail." I Googled that and found a couple fixes. The second fix was to enter "tccutil reset AppleEvents; tccutil reset SystemPolicyAllFiles" in Terminal. It now works.

Thanx for your assistance… greatly appreciated!

Ken

Thanks for your feedback. Happy that it works now.

If one of my posts served as a solution or major help to your issue/question, feel free to set the “solved” check mark at the bottom of that post.

And, of course, don’t hesitate to post any further questions on the topic, e.g. how to modify the AppleScript or whatever.