如何通过AppleScript设置当前Mail.app外发邮件的发件人?

smo*_*ris 6 macos applescript apple-mail

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

我试过这个:

tell application "Mail" to set sender of front outgoing message to "<my email address>"
Run Code Online (Sandbox Code Playgroud)

但我得到的错误信息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
Run Code Online (Sandbox Code Playgroud)

我得到{class:item}了回报,而不是像我期望的那样的"传出消息"对象.

有任何想法吗?

Mat*_*kar 5

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

相反,您可以使用GUI脚本来完成此任务,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
Run Code Online (Sandbox Code Playgroud)

menu item 6将第四行的更改为所需发件人列表中的任意数字(例如,如果您要使用此脚本更改为的发件人是所列的第四位发件人,请更改menu item 6menu item 4)。


更新:如果您很好奇,因为此答案已有两年之久了:截至2014-04-26,outgoing message仍无法获得/设置s 的属性,并且此解决方法仍可在OS X 10.9 Mavericks中使用。