AppleScript使用“邮件中的规则”将邮件移至邮箱

时间:2012-07-18 20:35:34

标签: applescript apple-mail

我看了看,但却无法找到这个看似简单的问题的答案(我也是AppleScript的新手)。基本上,我只想要一个脚本来设置规则并将消息移动到邮箱" Foo" (我的IMAP帐户中的邮箱)。这就是我所拥有的:

tell application "Mail"
set newRule to make new rule at end of rules with properties {name:"Foo Internal",   enabled:true}
tell newRule
    make new rule condition at end of rule conditions with properties {rule type:any recipient, expression:"internal_foo@foo.com", qualifier:does contain value}
    set move message to mailbox "Foo"
end tell
end tell

我已尝试过这条线的各种组合......

set move message to mailbox "Foo"

...包括指定IMAP帐户,将其设置为变量,等等。我不是程序员,但我真的想编写这些规则,因为我一直在工作时设置规则。有什么帮助吗?

1 个答案:

答案 0 :(得分:0)

您的脚本因两件事而失败:

  1. 忽略了将规则的should move message属性设置为true,这是move message操作实际“粘贴”所需的;
  2. 它没有正确定义目标邮箱的对象层次结构:您将需要accountapplication上下文,因为您位于定位规则的tell块内,不是邮件。
  3. 以下代码:

    tell application "Mail"
        set newRule to make new rule at end of rules with properties {name:"Foo Internal", enabled:true, should move message:true}
        tell newRule
            make new rule condition at end of rule conditions with properties {rule type:any recipient, expression:"internal_foo@foo.com", qualifier:does contain value}
            set move message to (mailbox "Foo" of account "Bar" of application "Mail")
        end tell
    end tell
    

    将适用于Mail 5.2(OS X 10.7.4中的库存)。