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

AppleScript中POSIX路径前导冒号致Outlook无法附加PDF

解决AppleScript中Word转PDF后Outlook无法附加文件的问题

问题核心

文件无法附加的根源是HFS路径转POSIX格式时出现错误:

  • 原HFS路径:Macintosh HD:Users:FAKEUSER:Desktop:automations:File Name.pdf
  • 错误转换结果::Macintosh HD/Users/FAKEUSER/Desktop/automations/File Name.pdf(开头多冒号,导致Outlook无法定位文件)

修复方案

1. 修正路径转换逻辑

Outlook的attachment对象file属性支持两种正确的路径格式,二选一即可:

方案A:直接用HFS路径转alias

修改Outlook部分的附件代码:

make new attachment with properties {file:outpath as alias}

方案B:正确转换为POSIX file对象

先将HFS路径转为标准POSIX字符串,再转为POSIX file对象:

-- 在Outlook的tell块内添加
set posixPDFPath to POSIX path of outpath
make new attachment with properties {file:POSIX file posixPDFPath}

2. 修复语法错误

原代码中CC收件人创建语句存在换行错误,修正为:

make new recipient with properties {email address:{address:selectedccmail}} at end of cc recipients of newMessage

完整修复后的代码

tell application "Microsoft Word"
    activate
    open file theDOCX

    set outpath to ("Macintosh HD:Users:FAKEUSER:Desktop:automations:" & selectedrecipient & ".pdf")
    set activeDoc to active document
    save as activeDoc file name outpath file format format PDF
    
end tell


tell application "Microsoft Outlook"
    set newMessage to make new outgoing message with properties {subject:"...", content:"..."}
    
    tell newMessage
        make new recipient at newMessage with properties {email address:{address:selectedemail}}
        -- 此处使用方案A的写法,也可替换为方案B代码
        make new attachment with properties {file:outpath as alias}
        
        delay 1
        
        make new recipient with properties {email address:{address:selectedccmail}} at end of cc recipients of newMessage
    end tell

    open newMessage
    get newMessage
end tell

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 16:00:17