使用AppleScript与Outlook创建带附件邮件的问题求助
修复Outlook AppleScript附件缺失问题
我帮你排查了这段AppleScript的问题,主要有几个关键调整点,咱们一步步解决:
问题分析
- 无效的变量初始化:脚本里
set whichFile to file这行完全多余,会给变量赋一个无效的初始值,直接删掉就好。 - 跨应用文件引用冲突:从
Finder获取的选中文件对象,直接在Microsoft Outlook的tell块里使用时,Outlook可能无法正确解析这个来自Finder的引用,导致附件无法添加。 - 附件属性赋值错误:原脚本里把文件转成
POSIX file的操作没必要,反而可能破坏文件引用,Outlook更适配alias类型的文件引用。
修复后的脚本
set mailBody to "<span>TEST</span>" set mailAdress to text returned of (display dialog "Mail Adress" default answer "" buttons {"OK"} default button 1) as string -- 获取Finder中选中的文件,去掉无效的初始化行 tell application "Finder" to set whichFile to selection repeat with aFile in whichFile tell application "Microsoft Outlook" set filename to name of aFile set theNewMessage to make new outgoing message with properties {subject:"TEST " & filename, content:mailBody} make new recipient at theNewMessage with properties {email address:{address:mailAdress}} -- 将Finder的文件对象转成Outlook能识别的alias引用 set fileAlias to aFile as alias -- 创建附件时直接使用alias类型的文件引用 make new attachment at the end of theNewMessage with properties {file:fileAlias} open theNewMessage end tell end repeat
额外说明
- 如果你的文件路径包含特殊字符,
alias引用依然能正常工作,比POSIX路径更稳定。 - 确保你选中的是文件而不是文件夹,Outlook的附件不支持直接添加文件夹(如果需要添加文件夹得先压缩成zip)。
内容的提问来源于stack exchange,提问作者Speedster




