The spam button is good for marking spam messages and banishing them to the spam folder.

I'm looking for a quick way to deal with messages that in my opinion are not quite spam. Mostly advertising emails from companies that I've dealt with in the past. I don't want them banished to the spam folder, but I don't want them cluttering my inbox.

I can:

  • Select a message.
  • Select Mail:Settings:Rules
  • Add rule. (Conveniently the message's from address is already entered.)
  • Select the mailbox I want to move the message to.
  • Select OK.

But that's more time than I want to take. I'd like a quick button or pull-down to add this kind of rule quickly and be done. Does anyone know of an extension, shortcut, automator, or script that does this? Hopefully, some script that adds or edits rules? I've seen several scripts working with sending messages or moving messages, but haven't found any that work with Mail's Rules. Aren't there any script handles for the rules?

1 Answer 1


I found the answer at https://superuser.com/a/1157607/1749037

tell application "Mail"
    (* The nameOfJunkRule is the string you gave in Mail.app. *)
    (* This is the part that begins to address the question. *)
    set markAsJunkRule to get rule "nameOfJunkRule"

    (* Get the selected messages in Mail.app *)
    set theMessages to the selection

    repeat with theMessage in theMessages
        (* Get the sender of the message. *)
        set senderAddress to sender of theMessage

        (* We want to make sure the address isn't already in the list. *)
        set foundAddress to false
        repeat with theCondition in rule conditions of markAsJunkRule
            if senderAddress = expression of theCondition then
                set foundAddress to true
                exit repeat
            end if
        end repeat

        (* If we need to add a new address to the rule. This is to finish the answer. *)
        if foundAddress = false then
            tell markAsJunkRule
                make new rule condition at end of rule conditions with properties {rule type:from header, qualifier:does contain value, expression:senderAddress}
            end tell
        end if
    end repeat
end tell

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .