MailMate "Smart Reply" Macro

I do a lot of email support using the most excellent MailMate. However, my preferred response formatting is for my response to come first, followed by the entire quoted text of the original email, followed by my signature...and MailMate does not support this. Instead, it tosses my signature at the very bottom, places the cursor above it, and the quoted text at the very top of the email (because of course the person I'm writing to wants to read their entire message before getting to my response...).

So now Keyboard Maestro is in my life I made a macro to automate the process, including attempting to add the salutation "Hello [First Name]," at the top and shifting focus to the messages list if I hit command-R while focus is in the sidebar (this practically saves me more wasted time than the rest of the macro):

Reply.kmmacros (16.0 KB)

Please note: this macro will only work for you if you have the following set in MailMate's settings (because it assumes things about the text in your response window):

It will also only work for English users, because it makes assumptions about what the "On such-and-such-date So-and-So wrote" line says.

The macro uses a lot of keypresses, so I'm not going to post an image of it because it's ridiculously long. Here's the basic logic flow:

  • Shift focus if the "Reply" menu item is disabled
  • Reply to the message, and choose "Reply" if the "do you want to reply to all" dialog opens
  • Delete the extra linebreak at the cursor, jump to the top of the message, and copy the line that states the date and sender
  • Parse the date/sender line with a short shell script and return whatever seems likely to be a first name (supports UTF-8, too!) or just a plain "Hello" if no first name is found
  • Add two returns before the quoted message, insert our salutation, and add two linebreaks after the salutation
  • If no first name was found, move the cursor up after the "Hello" so that I can add a name by hand (and if there isn't a name anywhere in the email, I can just arrow back down twice to reply)

Hope this is useful to others! It's been saving me so much time recently, I figured I should share it. It also might be a useful template if you use a different salutation, etc.

2 Likes

Hey Ian,

Looks good.

One thing – Keyboard Maestro has it’s own search/replace with regex – so there’s no especial need to shell out to Python.

–
Best Regards,
Chris

Does the replacement offer a conditional syntax? I wasn't able to find any information about what flavor of regex the regex search/replace was running, and the conditional replacement syntax that I am familiar with in other programs didn't work, which necessitated Python for properly falling back to a standard "Hello," salutation.

Keyboard Maestro uses the ICU Regular Expression system, the reference documentation is available via the Help menu in Keyboard Maestro.

I don’t know what you mean by “conditional syntax”, but a quick look at the regex doesn’t show anything that would be difficult.

Search & Replace variable responseLine
^On \d+ [a-zA-Z]+ \d{4}, at \d+:\d+, ([\w’-]+)(?: [\w '-]+)? wrote:$
$1

I assume re.U means unicode, which is always the case, and re.I means case insensitive, but if they mean something else there are various other regex flags you can set.

Can't you achieve that part using MailMate's preferences, by setting 'Default signature placement' to 'Bottom' and 'Caret placement' to 'Always at Top'?