So one of the downsides to corporate life can be dealing with the deluge of email. While Slack is the new hotness for communicating inside companies, when dealing with outside people or organizations email is still the lingua franca of communication. But the downside to that is that you sometimes have to deal with repetitive emails.
One in particular I have noticed over the last few years being more and more common is people reaching out to me wanting to get content on DealNews, or in some other way work with our marketing or business development teams. It is starting to get so common that I get it several times a month, and the reply is always the same: I don’t have editorial control over what content appears on the website, please reach out to these web addresses.
But typing this out every time is annoying. There should be a way to automate this. After all, anything worth doing twice is worth automating.
Surprisingly, there does not seem to be a way to have “templated responses” in Mail.app. This seems a curious omission given how otherwise surprisingly full featured the built-in mail client is. But we do have other options: namely we have Applescript.
After doing some reading and trial and error, this is what I came up with:
set theFile to ("Macintosh HD:Users:peckrob:Development:Dotfiles:data:mail:dealnews-marketing.txt") set theFileContents to paragraphs of (read file theFile) tell application "Mail" set theSignatureName to "dealnews" set theMessages to selected messages of first message viewer set theMessage to first item of theMessages set theOutgoingMessage to reply theMessage with opening window and reply to all tell theOutgoingMessage tell application "System Events" to tell process "Mail" set frontmost to true tell window 1 tell scroll area 1 tell UI element 1 tell group 3 tell static text 1 repeat with theItem in theFileContents keystroke theItem & return end repeat end tell end tell end tell end tell end tell end tell end tell end tell
So this is pretty hacky, so we’ll step through it.
First, we set the file path and read the file. Remember, Applescript is old and still uses the
:HFS path separators. In this case we read a file path into an array of paragraphs.
We open the selected email for a reply. This puts the text quoted in the body and inserts the cursor at the top of the message.
We descend the control tree hierarchy of the mail reply until we reach the text box, then loop the paragraphs from the file into the message.
I decided the best way to handle running it is Alfred. I can just type “marketing” and it pops up with the script. From there, hit Return and it runs the script and generates the reply email. You could optionally have it even send the email for you, but actions like that I want to take the human step of pushing “Send.”
Hat tip to this thread that helped me figure most of this out.