You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Mail 16中用AppleScript读取邮件主题失败问题排查

问题解决:Mail 16 + AppleScript 2.8 无法显示邮件主题弹窗

你的脚本能触发并显示"here",说明规则和循环逻辑没问题,问题出在display dialog subs as rich text这一行。

原因分析

新版本的AppleScript或Mail应用对display dialog的as rich text参数处理有变化:邮件主题(subject)本身是纯文本类型,强行指定as rich text会导致弹窗无法正常渲染,又因为Mail规则触发的脚本默认不显示错误提示,所以看起来无反应。

解决方案

方案1:移除as rich text参数

直接使用纯文本显示主题,这是最稳妥的方式,因为邮件主题本身就是纯文本:

using terms from application "Mail"
    on perform mail action with messages these_messages for rule this_rule
        tell application "Mail"
            display dialog length of these_messages as text
            repeat with an_email in these_messages
                display dialog "here"
                set subs to subject of an_email
                display dialog subs -- 移除as rich text
            end repeat
        end tell
    end perform mail action with messages
end using terms from

方案2:添加错误捕获排查问题

如果需要确认具体错误,可以给弹窗代码加上错误捕获,强制显示错误信息:

using terms from application "Mail"
    on perform mail action with messages these_messages for rule this_rule
        tell application "Mail"
            display dialog length of these_messages as text
            repeat with an_email in these_messages
                display dialog "here"
                set subs to subject of an_email
                try
                    display dialog subs as rich text
                on error errMsg
                    display dialog "错误信息:" & errMsg
                end try
            end repeat
        end tell
    end perform mail action with messages
end using terms from

方案3:显式转换为富文本(若需格式支持)

如果你的邮件主题确实包含富文本格式(极少情况),可以先将文本转换为富文本对象再显示:

using terms from application "Mail"
    on perform mail action with messages these_messages for rule this_rule
        tell application "Mail"
            display dialog length of these_messages as text
            repeat with an_email in these_messages
                display dialog "here"
                set subs to subject of an_email
                set rich_subject to subs as rich text
                display dialog rich_subject
            end repeat
        end tell
    end perform mail action with messages
end using terms from

内容的提问来源于stack exchange,提问作者Greg Humphrey

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.02 00:20:45