使用Applescript添加新规则电子邮件



我想创建一个苹果脚本,在Mac邮件应用程序中创建一个新规则,如果我收到一封电子邮件,并且电子邮件的标题是"测试",我希望启动一个苹果剧本。

这是我迄今为止的代码:

tell application "Mail"
    set newRule to make new rule at end of rules with properties {name:"test rule", Run applescript:"test.scpt"}
    tell newRule
       make new rule condition at end of rule conditions with properties {rule type:message content, qualifier:does contain value, expression:"test"}
    end tell
end tell

make行中第二个属性的名称为run script

试试这个

set applicationScriptsFolder to (path to library folder from user domain as text) & "Application Scripts:com.apple.mail:"
tell application "Mail"
    set newRule to make new rule with properties {name:"test rule", run script:alias (applicationScriptsFolder & "test.scpt")}
    tell newRule
        make new rule condition at end of rule conditions with properties {rule type:message content, qualifier:does contain value, expression:"test"}
    end tell
end tell

编辑:run script参数似乎需要脚本的完整路径。

奇怪的是,该脚本没有显示在"邮件首选项">"规则"中,但可以使用AppleScript读取该属性。

最新更新