How do I refer to a message that is in the frontmost window in Apple Mail? I have a Filemaker script that saves a report as PDF and attaches it to a new email message in a new window. Now I want to use Applescript to enter email addresses in the To: and CC: fields in the new email message containing the attachment.
All the examples I find refer to making a “new outgoing message” such as this:
tell application "Mail"
set newMessage to make new outgoing message with properties {subject:theSubject, content:theMessage}
tell newMessage
set sender to theSender
make new to recipient at end of to recipients with properties {address:theRecipient}
end tell
end tell
This won’t work since I already have a new message. All I want to do is enter new recipients. But it seems I need to refer to this message as something more than “the front window”.
Any ideas?
Hey Markman,
I was wondering if you figured out how to refer to the message in the frontmost window of Mail. I am looking for the same thing – except that I need to refer to the content of that message for my workflow. If you or anybody knows the answer to this, please let know.
All best,
Alex
Psycho,
A very helpful “dev_sleidy” came up with a solution on Apple’s Applescript boards.
http://discussions.apple.com/message.jspa?messageID=3064506#3064506
The key seems to call it “(outgoing message 1)”. The script he came up with is very elaborate. For example, he takes into account if you have multiple Mail windows open and looks for the one called “New Message”.
My sense is scripting Mail is different than other applications because each message is really a record in a database not a bunch of documents in windows like Safari or TextEdit.
He also had to use System Events. In the end I found a simpler more elegant solution in Filemaker without needing applescript.
Good Luck,
Mark
Many thanks for your quick response, Mark! I will look into that solution.
All best