如何通过 AppleScript 设置当前 Mail.app 外发消息的发件人?
我想编写一个 AppleScript 来设置 Apple 的 Mail.app 中当前传出消息的发件人。
我已经尝试过这个:
tell application "Mail" to set sender of front outgoing message to "<my email address>"
但我收到错误消息 error“邮件出错:无法将项目的发件人设置为任何。”编号 -10006 从项目发件人到任何
这对我来说没有意义。
当我尝试按如下方式询问前面的传出消息时:
tell application "Mail" to get properties of front outgoing message
我得到 {class:item}
作为回报,而不是像我期望的那样的“传出消息”对象。
有什么想法吗?
I'd like to write an AppleScript to set the sender of the current outgoing message in Apple's Mail.app.
I've tried this:
tell application "Mail" to set sender of front outgoing message to "<my email address>"
but I get the error message error "Mail got an error: Can’t set sender of item to any." number -10006 from sender of item to any
which doesn't make sense to me.
When I try to interrogate the front outgoing message as follows:
tell application "Mail" to get properties of front outgoing message
I get {class:item}
in return, instead of an "outgoing message" object like I'd expect.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
不幸的是,您无法获取或设置
传出消息的属性< /code> Mail with Applescript 对象。
相反,您可以使用 GUI 脚本来完成此操作,这是一种直接操作窗口元素的解决方法。
此代码应该适合您:
将第四行上的
菜单项 6
更改为您所需的发件人列表中的任意数字(例如,如果您要使用此脚本更改为的发件人是第四个)列出其中一项,将菜单项 6
更改为菜单项 4
)。更新:如果您很好奇,因为这个答案已有两年多了:截至 2014 年 4 月 26 日,获取/设置
传出消息
的属性仍然是不可能,这个解决方法在 OS X 10.9 Mavericks 中仍然有效。Unfortunately, you cannot get or set the properties of the
outgoing message
object of Mail with Applescript.Instead, you can accomplish this with GUI scripting, a workaround that directly manipulates window elements.
This code should work for you:
Change the
menu item 6
on the fourth line to whichever number in the list your desired sender is (e.g., if the sender you want to change to with this script is the fourth one listed, changemenu item 6
tomenu item 4
).Update: If you're curious, since this answer is over two years old: as of 2014-04-26, getting/setting the properties of
outgoing message
s is still impossible and this workaround still works in OS X 10.9 Mavericks.我认为这有点复杂。我自己的实验与 Alan Kimelman 在此线程,AppleScript 对于脚本从头开始创建的传出消息按预期工作。例如,以下代码可以工作:
但是,如果消息是通过其他方式创建的(例如,我通过告诉 Safari 通过电子邮件共享来创建 HTML 消息),则 Matthew McVickar 认为 AppleScript 已损坏的说法是正确的。您无法设置或获取任何属性,并且它还拒绝发送命令。
I think it's a little more complicated. My own experiments agree with the conclusion of Alan Kimelman in this thread, that AppleScript works as expected for outgoing messages created from scratch by the script. For example, the following code works:
However, if the message is created by other means (for example, I create HTML messages by telling Safari to Share via Email), then Matthew McVickar is correct that AppleScript is broken. You can't set or get any properties, and also it refuses the send command.
实际上,您可以按照此处所述设置传出消息的发件人:
通过 Applescript 发送电子邮件时发件人不正确
Actually you can set the sender of an outgoing message as described here:
Incorrect sender when sending Email via Applescript
您无法设置外发消息的发件人,这有点令人沮丧。
这是我多年前写的并且经常使用的马修脚本的更通用版本。 是一个字符串,其中包含您在“From:”弹出窗口中看到的内容,例如
(如果您不执行大量 GUI 脚本编写,那么要获得此类内容的详细信息是非常棘手的。)
参数 我使用参数化处理程序是使用按键宏工具为每个电子邮件地址绑定按键组合。每个都执行一个 AppleScript,该脚本加载包含上述处理程序的文件并使用特定的电子邮件地址调用它。例如:
It is more than a little frustrating that you can't set the sender of an outgoing message.
Here's a more general version of Matthew's script that I wrote many years ago and have used frequently. The argument is a string that contains exactly what you see in the "From:" pop up, e.g.
(It is very tricky to get the details of something like this right if you don't do a lot of GUI scripting.)
The reason I use a parameterized handler is that I use keystroke macro facilities to bind a keystroke combination for each of my email addresses. Each executes an AppleScript that loads the file containing the above handler and invokes it with a specific email address. For example:
试试这个吧。
更新:我会查看Mail的脚本字典,看看你能做什么和不能做什么。那里提供的信息可能会有所帮助。 :)
Try this instead.
UPDATE: I would look in Mail's scripting dictionary and see what you can and cannot do. The information provided there might help. :)
我提供的 GUI 脚本示例是一个使用“Watch Me Do”命令的 Automator 脚本。我不明白它到底是如何工作的,但它表面上记录了鼠标移动和 GUI 交互,然后在运行时重新执行您记录的内容。不幸的是,我在运行脚本时遇到了明显的延迟。要求它运行后,有时会在5秒或更长时间后执行,这显然无法使用。
GUI 脚本方法几乎是即时启动的,而且看起来更干净(无需鼠标移动)。我推荐它。
An alternative to the GUI scripting example I provided would be an Automator script that utilizes the 'Watch Me Do' command. I don't understand exactly how it works underneath the hood, but it ostensibly records mouse movement and GUI interaction and then reenacts what you recorded it when it runs. Unfortunately, I experienced significant lag when running the script. After asking it to run, it would sometimes execute after 5 or more seconds, which is clearly unusable.
The GUI scripting method is almost instantaneous and cleaner-looking (no mouse movement) to boot. I recommend it.
使用 AppleScript 使用您喜欢的任何传出地址(至少是在 Mail.app 首选项中配置的地址)创建新的传出邮件非常简单。
这里的讨论围绕着在创建消息后尝试(错误地)更改它。相反,请在创建消息时指定它:
引号中的文本需要与任何已配置帐户的真实姓名和电子邮件地址(V 形)相匹配。如果没有匹配,Mail.app 将使用默认地址
It's trivial to use AppleScript to create a new outgoing message with any outgoing address that you like (well, at least, the ones configured in your Mail.app preferences).
The discussions here hinge around trying (incorrectly) to change it after the message is created. Instead, specify it when you create the message:
The text in quotes needs to match both the real name and the email address (in chevrons) of any configured account. If there's no match, Mail.app will use the default address