Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Creating service to insert text into email message

Hi,


I’ve done a few simple services in Automator, but I’m struggling with a more complex one:


I want to create a service for Apple Mail to insert the contents of a plain text document (.txt) into an email reply at the current cursor position. The text documents are stored in the user’s Documents > Replies folder named something like "standard-reply.txt", "reply-01.txt" etc.


Ideally would like to be able to select the service and be prompted with an Open File dialog allowing me to select the text document to be inserted.


Any help would be very much appreciated.



Martin

Posted on Jan 30, 2012 9:39 PM

Reply
Question marked as Best reply

Posted on Jan 31, 2012 5:58 AM

If you're not wedded to implementing this yourself, the TextExpander tool offers this capability, and you can also enable and use the text substitutions mechanism within mail to implement snippets substitution; boilerplate responses. And there are other alternatives. There are also some support tools available which pre-scan mail for FAQs, depending on the volume of messages arriving.

8 replies
Question marked as Best reply

Jan 31, 2012 5:58 AM in response to Martin S.

If you're not wedded to implementing this yourself, the TextExpander tool offers this capability, and you can also enable and use the text substitutions mechanism within mail to implement snippets substitution; boilerplate responses. And there are other alternatives. There are also some support tools available which pre-scan mail for FAQs, depending on the volume of messages arriving.

Feb 1, 2012 11:50 AM in response to Martin S.

The following service seems to do what you are asking for:


User uploaded file


Here's the script:


set theFolder to (path to documents folder as text) & "Replies:" as alias

set theFile to choose fileof type "txt" default locationtheFolder

set the clipboard to (readtheFileasUnicode text)

tell application "Mail" to activate

tell application "System Events" to keystroke "v" using {command down}


Message was edited by: Pierre L.

Feb 4, 2012 7:49 AM in response to Martin S.

Many thanks for your feedback, Martin.


You're right: the correct statement should have been simply

set the clipboard to (readtheFile)

I'm glad that you were able to fix the encoding issue.


That's my bad! The problem is that I tested the script with plain text files made with TextEdit and saved using the Unicode (UTF-16) plain text encoding. The default Unicode (UTF-8) encoding used by TextEdit doesn't seem to be able to cope with characters such as "à" or "é", unavoidable in French, which it saves as "√†" and "√©" in plain text files.


Of course, I could have avoided the issue if I only had created the text files like follows:

set F to open for accesstheFile with write permission

write "a à e é" to F

close accessF


Message was edited by: Pierre L.

Feb 5, 2012 5:00 AM in response to Pierre L.

Hi Pierre,


another question…


when right-clicking in a message’s window to invoke the contextual menu I see Mail’s two default services, Import Image and Capture Selection from Screen, listed at the bottom, but not the new service I created as per your instructions.


I was going to compare these services to find out what makes them appear in the contextual menu, but I wasn’t able locate them. Any ideas?

Feb 5, 2012 9:29 AM in response to Martin S.

You could make the service appear in the contextual menu by selecting “text” (the default choice, actually) in the “Service receives selected” drop-down menu, instead of “no input”. However, the service will then appear only if some text is selected, and not with just the insertion point.


Btw, maybe I should have told you I know practically nothing about Automator and services. I use AppleScript with the Script Menu. 😕


Message was edited by: Pierre L.

Creating service to insert text into email message

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.