7

我想编写一个 AppleScript 来设置 Apple 的 Mail.app 中当前外发邮件的发件人。

我试过这个:

tell application "Mail" to set sender of front outgoing message to "<my email address>"

error "Mail got an error: Can’t set sender of item to any." number -10006 from sender of item to any但我收到了对我来说没有意义的错误消息。

当我尝试如下询问前面的传出消息时:

tell application "Mail" to get properties of front outgoing message

我得到{class:item}了回报,而不是我期望的“传出消息”对象。

有任何想法吗?

4

7 回答 7

5

不幸的是,您无法outgoing message使用 Applescript 获取或设置 Mail 对象的属性。

相反,您可以使用 GUI 脚本来完成此操作,这是一种直接操作窗口元素的解决方法。

此代码应该适合您:

tell application "System Events"
  tell process "Mail"
    click pop up button 1 of window 1
    click menu item 6 of menu 1 of pop up button 1 of window 1
  end tell
end tell

将第四行的更改menu item 6为列表中您想要的发件人的任何数字(例如,如果您要使用此脚本更改为的发件人是列出的第四个,则更menu item 6改为menu item 4)。


更新:如果你很好奇,因为这个答案已经有两年多了:截至 2014-04-26,获取/设置outgoing messages 的属性仍然是不可能的,并且这种解决方法仍然适用于 OS X 10.9 Mavericks。

于 2011-10-07T10:41:28.207 回答
4

我认为这有点复杂。我自己的实验同意 Alan Kimelman 在此线程中的结论,即 AppleScript对脚本从头开始创建的传出消息按预期工作。例如,以下代码有效:

tell application "Mail"
set newMessage to (a reference to (make new outgoing message))
tell newMessage
    make new to recipient at beginning of to recipients ¬
        with properties {address:"hello@world.com", name:"The World"}
    set the sender to "Jerry Krinock <jerry@sheepsystems.com>"
    set the subject to "A Test"
    set the content to "This is only a test."
    send
end tell
end tell

但是,如果消息是通过其他方式创建的(例如,我通过告诉 Safari 通过电子邮件共享来创建 HTML 消息),那么 Matthew McVickar 认为 AppleScript 已损坏是正确的。您无法设置或获取任何属性,并且它也拒绝发送命令。

于 2014-06-05T00:23:28.943 回答
3

您无法设置外发邮件的发件人,这有点令人沮丧。

这是我多年前编写并经常使用的 Matthew 脚本的更通用版本。参数是一个字符串,其中包含您在“From:”弹出窗口中看到的内容,例如

"Mitchell L Model <dev@software-concepts.org>"

(如果您不编写大量 GUI 脚本,那么要正确获取此类内容的详细信息是非常棘手的。)

to setFrom(address)
    tell application "System Events"
        activate application "Mail"
        tell pop up button "From:" of window 1 of application process "Mail"
            click
            tell menu item address of menu 1 to click
        end tell
    end tell
end setFrom

我使用参数化处理程序的原因是我使用击键宏工具为我的每个电子邮件地址绑定击键组合。每个都执行一个 AppleScript,加载包含上述处理程序的文件并使用特定的电子邮件地址调用它。例如:

property util : load script alias (((path to home folder) as text) & "Scripts:Utilities.scpt")

util's 's setFrom("Mitchell L Model <dev@software-concepts.org>")
于 2013-07-18T22:02:55.230 回答
3

实际上,您可以按照此处所述设置外发邮件的发件人: 通过 Applescript 发送电子邮件时发件人不正确

于 2014-12-13T11:52:35.220 回答
1

使用 AppleScript 使用您喜欢的任何外发地址(嗯,至少是在您的 Mail.app 首选项中配置的地址)创建一条新的外发邮件是微不足道的。

这里的讨论围绕在创建消息后尝试(错误地)更改它。相反,在创建消息时指定它:

set new_m to make new outgoing message with properties {sender:"My Name <me@my.com>"}

引号中的文本需要匹配任何已配置帐户的真实姓名和电子邮件地址(V 形)。如果没有匹配,Mail.app 将使用默认地址

于 2015-03-23T20:25:25.910 回答
0

试试这个。

tell application "Mail" to make new outgoing message with properties {sender:"<your_email_address>", visible:true}

更新:我会查看 Mail 的脚本字典,看看你能做什么,不能做什么。那里提供的信息可能会有所帮助。:)

于 2011-07-29T19:56:36.677 回答
0

我提供的 GUI 脚本示例的替代方法是使用“Watch Me Do”命令的 Automator 脚本。我不明白它到底是如何工作的,但它表面上记录了鼠标移动和 GUI 交互,然后在运行时重新制定你记录的内容。不幸的是,我在运行脚本时遇到了明显的延迟。要求它运行后,有时会在 5 秒或更长时间后执行,这显然是无法使用的。

GUI 脚本方法几乎​​可以立即启动并且看起来更干净(没有鼠标移动)。我推荐它。

于 2011-10-07T11:06:52.773 回答