This can be done if we make two rather weak assumptions: that the message you are working on is ahead, and that the theme of all draft messages is unique. Then, before running the script, save the message you are working on; this will put it in the draft mailbox. Then, since the message object is the window name, we can easily access it; and since we can easily access the draft mailbox, we can combine the two. This gives us:
tell application "Mail" set msgs to messages of drafts mailbox ¬ whose subject is (name of window 1 as string) if (count of msgs) = 1 then
You can probably make a script save the front window itself, and it wouldn't surprise me if the freshly saved message is always the first element of the draft mailbox, but this remains as an exercise for the reader :-)
source share