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?
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:
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
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, change menu item 6
to menu 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.