Applescript to paste text into an email reply in Mail (Tiger)

I want to send the same text reply to certain email messages in Mail (OS 10.4.10) without having to retype it each time. In Eudora the feature was called “Reply With.” I guess I could copy the reply from a text file and paste it into the reply message each time, but I’m hoping for a more automatic way to do this. Does anyone know of an existing Applescript that would do this or be able to write one for me, please? Thanks in advance.:slight_smile:

Model: 24" 2.8 GHz Intel iMac (mid 2007)
AppleScript: ??
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)

Hi,

unfortunately it is not possible to change some things in a new message created with the reply command.
I would create the message “manually” using a rule, like this


property theContent : "Hello, this is an automatic reply"

using terms from application "Mail"
	on perform mail action with messages theMessages for rule theRule
		repeat with eachMessage in theMessages
			tell application "Mail"
				tell eachMessage to set {theSender, theAddress, theSubject} to {extract name from sender, extract address from sender, subject}
				set newMessage to make new outgoing message with properties {subject:"Re: " & theSubject, content:theContent, visible:true}
				tell newMessage
					make new to recipient at end of to recipients with properties {name:theSender, address:theAddress}
				end tell
				activate
				send newMessage
			end tell
		end repeat
	end perform mail action with messages
end using terms from

Thanks for reply, Stefan.

Now, because I don’t understand much about Applescripts, please tell me how to use your script.

If I want to send all the text (less than a page long) from a file I saved called ABC.doc and use it as a reply for new messages #1, 2, and 4, but NOT #3 in my Inbox, how do I use the script to do that? I don’t want this reply to go to every message I receive, only certain ones that I manually select. I might want to use ABC.doc as a reply for one message and XYZ.doc in reply to another message.

And what do you mean by “using a rule”?

Thanks again.

In Mail.app you can use rules to automate some things like
moving certain messages to certain mailboxes oder save the attachment(s) automatically.

If you want to do this manually, try this example.


set textA to ((path to desktop as Unicode text) & "textA.txt")
set textB to ((path to desktop as Unicode text) & "textB.txt")

set tFile to button returned of (display dialog "choose the text files" buttons {"Cancel", "textA", "textB"})
if tFile is textA then
	set theContent to read file textA
else
	set theContent to read file textB
end if

tell application "Mail" to set theMessages to selection
repeat with eachMessage in theMessages
	tell application "Mail"
		tell eachMessage to set {theSender, theAddress, theSubject} to {extract name from sender, extract address from sender, subject}
		set newMessage to make new outgoing message with properties {subject:"Re: " & theSubject, content:theContent, visible:true}
		tell newMessage
			make new to recipient at end of to recipients with properties {name:theSender, address:theAddress}
		end tell
		activate
		send newMessage
	end tell
end repeat

Enable the global script menu in /Applications/AppleScript/AppleScript Utility.app/ an put the script into ~/Library/Scripts
The script expects two plain text files (it would be a bit more complicated using word documents) textA.txt and textB.txt on the desktop.
Select the messages you want in Mail and run the script form the script menu.
You will be prompted to choose the text file