Applescript 不再将文件附加到电子邮件

问题描述 投票:0回答:1

我有一个 Applescript,直到最近它在生成和发送纯文本电子邮件以及附加 jpg 文件(约 119 KB)方面都运行良好。自从将我的系统升级到 Mac OS Sonoma 14.4.1 后,attach 命令不再执行任何操作。我在网上搜索了解决方案,但到目前为止还没有找到解决方案。有谁知道这样的故障吗?

我一直在寻找 Applescript 向电子邮件添加附件的替代方法。我在附加命令之前和之后都放置了额外的延迟时间(很多秒)。我一直在使用一个脚本,该脚本被缩减为一个用于发送电子邮件的框架。没有运气。

这是我的骨架脚本的副本:

set fileName to "<path to my file>" // Actual file path inserted between quotes

tell application "Mail"
    activate
    set mymail to make new outgoing message at the beginning of outgoing messages with properties {subject:"A Test"}
    tell mymail
        make new to recipient at beginning of to recipients with properties {address:"<my email address>"} // Again, my email address (for testing) inserted between quotes
        delay 1 // I've tried as much as 16 seconds
        set content to "This is a test."
    end tell
    
    set visible of mymail to true
    
    tell mymail to make new attachment with properties {file name:fileName} at after last paragraph
    
    delay 1 // I've also tried up to 16 seconds here
    activate
    send mymail
end tell

Applescript 完美地创建和发送电子邮件。我发现它确实找到了该文件(通过显示对话框命令)。并且在升级到最新版本的Sonoma之前,它附加了jpg文件;但现在它只发送不带附件的电子邮件。我非常感谢任何想法!

email applescript attachment
1个回答
0
投票

我在运行脚本时发现的问题是

fileName
(您在
{file name:fileName}
中传递给邮件)是一个普通字符串,出于沙箱原因,这不起作用。邮件无法读取文件(不幸的是无提示地),并且您没有收到任何附件。

解决方案是将文件 specifier 传递给 Mail — 当您这样做时,系统知道它应该与“make”命令一起传递该文件的沙箱扩展。根据路径字符串的格式,它应该是

set fileName to alias "..."
(对于老式冒号分隔的路径)或
set fileName to POSIX file "..."
(对于 UNIX 样式斜杠分隔的路径)。

我很困惑为什么它以前有效 - Mail 已在相当多的版本中被沙箱化 - 除非您在运行脚本之前已经在 Mail 中使用了相同的文件。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.