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

macOS 15.5 Sequoia下Mail 16.0 PDF附件打开脚本故障求助

修复Mail 16.0中打开PDF附件的AppleScript脚本

原脚本无响应的核心原因是Mail 16.0限制了直接访问附件的content属性,加上路径处理逻辑存在漏洞,导致附件无法正常保存并打开。以下是修复后的脚本:

tell application "Mail"
    set selectedMessages to selection
    if selectedMessages is {} then return
    
    set theMessage to first item of selectedMessages
    -- 直接筛选PDF附件,减少循环冗余
    set theAttachments to every mail attachment of theMessage whose name ends with ".pdf"
    
    if theAttachments is {} then return
    
    set theAttachment to first item of theAttachments
    set tempFolder to (path to temporary items from user domain) as POSIX path
    set filePath to tempFolder & (name of theAttachment)
    
    -- 使用Mail原生的保存命令,避开权限限制
    save theAttachment in POSIX file filePath
    
    tell application "Preview"
        activate
        open POSIX file filePath
    end tell
end tell

修复要点:

  • 用Mail内置的筛选逻辑直接定位PDF附件,无需额外循环判断
  • 采用Mail原生的save命令保存附件,解决原脚本手动读写文件的权限问题
  • 全程使用POSIX路径处理,避免文本路径与POSIX路径转换时的错误
  • 激活Preview后再打开文件,确保窗口正常显示

使用提示:

运行脚本前需确保已选中至少一封带有PDF附件的邮件;若仍无法运行,检查系统「安全性与隐私」设置是否允许脚本控制Mail和Preview。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.12 21:33:13