3

我有以下由 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。

4

2 回答 2

0

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


您能否运行 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"

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

您也可以查看此处此处此处,以验证并仔细检查规则是否设置正确。

于 2018-01-24T07:58:30.670 回答
0

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

一种可能的解决方法是将 a 添加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
于 2018-02-01T15:53:26.243 回答