Mail.app';的规则正在向AppleScript发送错误的消息

Mail.app';的规则正在向AppleScript发送错误的消息,applescript,rules,apple-mail,Applescript,Rules,Apple Mail,我有以下由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 ms

我有以下由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
如果我选择了一条消息,右键单击并选择“应用规则”,它将正常工作。但是,如果脚本是由传入消息触发的,则消息中似乎有随机消息

规则如下:

我如何得到正确的信息


我将High Sierra与Mail 11.2一起使用。

由于您的脚本将迭代您的邮件,我希望您的邮件不会按日期排序。。。因此,当您运行脚本时,它将使用第一个元素(而不是最近的)


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

然后验证脚本是否有效


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

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"
在运行脚本之前按日期对电子邮件进行排序,以便获得正确的消息


您还可以查看一下,验证并再次检查规则是否正确设置。

显然,使用规则处理传入消息是一个异步过程。调用执行邮件操作上的
时,消息尚未完全更新。只有部分数据立即可用

一种可能的解决方法是在脚本中添加
延迟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

这个解决方案不起作用。即使在排序之后,它仍然会选择一条随机消息。请记住,脚本是由传入事务的邮件规则触发的。我们希望看到规则选择的邮件,但收到不同的邮件时,您是否可以制作规则的打印屏幕,因为规则条件似乎未正确设置?图像已添加到原始帖子中。请将其按预期方式写在一行中!:<代码>告诉应用程序“系统事件”单击菜单项的“日期”菜单项的“排序依据”菜单项的“排序依据”菜单栏项的“视图”菜单栏1的“视图”处理“邮件”
缩进有时可能会有帮助,但我会根据您的建议进行更改@用户3439894,你知道为什么他的过滤器不工作吗?每次触发时,随机消息都是一样的吗?