Applescript更新现有邮件规则


3

MacOS Sierra。

这似乎可以基于以下脚本来创建新规则:

tell application "Mail"
    set newRule to make new rule at end of rules with properties { ... }
    tell newRule
        make new rule condition at end of rule conditions with properties { ... }
    end tell
end tell

我希望能做的是这样的:

tell application "Mail"
    set existingRule to (* get a specific rule already in Mail Preferences *)
    tell existingRule
        make new rule condition at end of rule conditions with properties {rule type:message content, qualifier:does contain value, expression:"woohoo"}
    end tell
end tell

我似乎无法找到的是一种检索已存储规则的方法。


您是否正在尝试编写自动检查新电子邮件的脚本?
music2myear 2016年

@ music2myear:不。我试图找出如何使用脚本更新现有规则。下面的答案是正确的 - 我花了很长时间才找到一条迂回的路线,然后想出来。
Josh Bruce

1
凉。我很高兴你能够弄明白并在这里记录下来。
music2myear 2016年

Answers:


3

对于此示例,我们尝试获取电子邮件的发件人,然后将其附加到电子邮件规则,如果电子邮件位于列表中,则该规则执行相同的操作。

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
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.