I have a simple script for Mail.app that seeks to redirect a given message and modify the subject by appending a string. The catch is I don’t seem to be able to grab the reference to the new outgoing message. Supposed this should work, yes?
tell application "Mail"
set thisMsg to message 1 of mailbox "INBOX" of account "Blah"
set thatMsg to redirect thisMsg with opening window
get thatMsg
end tell
Well, if I run this, I get an error saying that thatMsg is undefined. It seems even though the dictionary says that the result of redirect should be a reference to an outgoing message, but when stepping through the script, I can confirm that the set thatMsg to redirect thisMsg with opening window line yields no result. Is this something I’ve botched up or can someone else confirm this?
Your script worked perfectly for me, when I deleted the final line:
tell application "Mail"
set thisMsg to message 1 of mailbox "INBOX" of account "MacScripter"
set thatMsg to redirect thisMsg with opening window
end tell
It opened up a window with the correct message, and the cursor was in the ‘To:’ box, awaiting an address.
The good news is that there’s nothing wrong with what you’re doing. The bad news is that a bug in Mail evidently prevents it from returning a reference (as it should) to a new message created using the forward, redirect or reply commands.
I don’t do much AppleScript work, so I’m just trying anything I can think of at this point. Is there a way to get the message id of an open message? That might be a workaround, although I don’t really want to see every message that’s being redirected flash by.
Update: I’m assuming that the reason this doesn’t work is that as of Mac OS X 10.4.x (Tiger), each individual message has an unique message ID number that’s used as the .emlx filename stored on disk (so that each message is indexed appropriately by Spotlight, as opposed to Panther and earlier which stored messages grouped together in the .mbox format) and so a new, unsaved message message doesn’t have a message ID? Is this correct? If so, I guess I’ll have to attack this issue as another exercise in GUI scripting.