Trouble creating scripted reply in Mail

Hi Everyone!
I’m trying to script Mail for the first time and I’m having troubles on what should be pretty straight forward. I’ve assigned an applescript to a rule:


on perform_mail_action(theData)
	tell application "Mail"
		set messageList to |SelectedMessages| of theData
		set mCount to the count of messageList
		repeat with i from 1 to mCount
			set theMessage to item i of messageList
			set theContent to the content of theMessage
			set theSubject to the subject of theMessage
			try
				set theReply to reply theMessage 
			on error errMsg number errNum
				set the result to display dialog errMsg buttons {"OK"}
			end try
		end repeat
	end tell
end perform_mail_action

and when I apply the rule from the menu to test it I get an “Apple event handler failed.” message when theReply message is created. The same thing happens if I try to create a new outgoing message. Any help would be greatly appreciated.

Hi,

in a mail rule any user interaction like display dialog is not supported.
And in Leopard creating an outgoing message in a rule is broken.

Thanks for the info! I spent hours searching the web about scripting Mail and this is the first I’ve heard of this issue. Is there a workaround? I need to generate the reply message dynamically. I’ve been using Entourage to automatically reply to incoming messages, but it keeps forgetting the password for the account, and I was hoping Mail would do a better job.

BTW I noticed that there was an issue with dialog boxes, but for some reason the dialog box with just the OK button worked. It was useful for debugging.

You can find a workaround here in Code Exchange

Thanks for the tip. And thanks for pointing out the code exchange. I’d never looked in there before.