Templated Mail Replies in macOS Mail.app

This is an old post!

This post is over 2 years old. Solutions referenced in this article may no longer be valid. Please consider this when utilizing any information referenced here.

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.

  1. 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.

  2. 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.

  3. 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.

Did this article help you out?

That's great! I don't earn any money from this site - I run no ads, sell no products and participate in no affiliate programs. I do this solely because it's fun; I enjoy writing and sharing what I learn.

All the same, if you found this article helpful and want to show your appreciation, here's my Amazon.com wishlist.

Read More

Proxying CUPS IPP using nginx

So I have this older Dell laser printer, a B1160w. It was released back in 2012, but it is a totally fine home printer for when I occasionally need to print something and it still works great after all these years, so I see no compelling reason to buy a new one. But there’s a problem: macOS support. Namely, no drivers have been released for macOS since 2017. Starting with Catalina, Apple started requiring code signing for executables, and the official Dell driver has an executable in it that refuses to execute because it isn’t signed. And despite my best efforts, short of turning off Gatekeeper entirely, I was not able to get it to work. But the printer itself is fine; there is absolutely no reason to create additional electronic waste purely for software reasons. But thanks to open-source software, we have another options: CUPS.

Solving CSSMERR_TP_CERT_EXPIRED error on OS X Installation

I have an old iMac that has been sitting unused upstairs for awhile, that I decided to finally get rid of. Before putting it on Craigslist, like any good computer owner, I wiped the drives and went to reinstall the most recent version of OS X/macOS that this old machine would support. In this case, this was El Capitan. But when I went to install, I kept getting an error about the OS not being able to install. Popping the log window open, I found an entry called CSSMERR_TP_CERT_EXPIRED. This would seem to be a prime suspect.