【问题标题】:Mail.app's rules are sending the wrong messages to AppleScriptMail.app 的规则正在向 AppleScript 发送错误消息
【发布时间】:2018-06-26 13:02:08
【问题描述】:

我有以下由 Mail.app 规则触发的 AppleScript:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with msg in theMessages
            set theText to subject of msg & return & content of msg & date sent of msg
            display dialog (theText)
        end repeat
    end perform mail action with messages
end using terms from

如果我选择一条消息,请右键单击并选择“应用规则”它可以正常工作。但是,如果脚本是由传入的消息触发的,那么消息中似乎有一条随机消息。

这里是规则:

我如何获得正确的信息?

我正在使用带有 Mail 11.2 的 High Sierra。

【问题讨论】:

  • 每次触发时随机消息是否相同?

标签: applescript rules apple-mail


【解决方案1】:

由于您的脚本将遍历您的邮件,我希望您的邮件不会按日期排序...因此,当您运行脚本时,它将采用第一个元素(而不是最新的)


您能否运行 Mail,然后按日期对电子邮件进行排序(最新的在顶部),然后退出并重新运行 Mail(再次检查配置是否已保存)

然后验证您的脚本是否有效。


如果不想手动设置过滤器,可以根据this在开头添加如下脚本:

tell application "System Events" to click menu item "Date" of menu "Sort By" of menu item "Sort By" of menu "View" of menu bar item "View" of menu bar 1 of process "Mail"

在运行脚本之前按日期对电子邮件进行排序以获得正确的消息。

您还可以查看 hereherehere 以验证并仔细检查规则是否正确设置。

【讨论】:

  • 此解决方案不起作用。即使在排序之后,它仍然会选择一条随机消息。请记住,该脚本是由传入交易的邮件规则触发的。我们希望看到规则选择的消息,但收到不同的消息,
  • 您能否制作一个规则的打印屏幕,因为似乎规则条件设置不正确?
  • 图片已添加到原始帖子中。
  • 按原样写在一行中!:tell application "System Events" to click menu item "Date" of menu "Sort By" of menu item "Sort By" of menu "View" of menu bar item "View" of menu bar 1 of process "Mail"
  • 缩进有时会有所帮助,但我会根据您的建议进行更改。 @user3439894,你知道他的过滤器为什么不起作用吗?
【解决方案2】:

显然,使用规则处理传入消息是一个异步过程。当on perform mail action 被调用时,消息还没有完全更新。只有部分数据立即可用。

一种可能的解决方法是将delay 1 添加到脚本中。这让 Mail 有一秒钟的时间来完成更新消息。下面是脚本的样子:

using terms from application "Mail"
    on perform mail action with messages theMessages for rule theRule
        repeat with msg in theMessages
            -- delay a bit of time for msg to load
            delay 1

            set theText to subject of msg & return & content of msg & date sent of msg

            — do other processing

        end repeat
    end perform mail action with messages
end using terms from

【讨论】:

    猜你喜欢
    • 2021-10-30
    • 2011-11-10
    • 1970-01-01
    • 2015-09-02
    • 2011-10-02
    • 2013-11-16
    • 1970-01-01
    • 1970-01-01
    • 2018-04-29
    相关资源
    最近更新 更多