Scripting replies

Thanks to TextExpander, I started looking for ways to improve productivity in another app I use everyday: Apple Mail. My problem is much in line with Elliot Jay Stocks, when he says the following:

Like many people, I find myself writing the same thing over and over and over again, with very subtle alterations.

Fortunately, Felix Geisendorfer shows how to automate parts of your reply, where for instance, when you hit the reply button, and trigger a TextExpander (AppleScript) snippet, it automatically pulls the name you’re replying to. In the example below, I have assigned ;re as a text-expansion trigger, powered by AppleScript, to pull salutation text and a “thank you” phrase to start the conversation; ;ks to pull signature text in-place.)

Autoreply in Apple Mail

Here’s the snippet I am using, which is entirely based on Felix’s, with subtle changes in text and number of insert lines:

tell application "Mail"
    set selected to selection
    set msg to item 1 of selected
    set sentBy to (sender of msg)
    "Hi " & word 1 of sentBy & ", \n\nThank you for your email.\n"
end tell

From Outlook Express to Apple Mail

  1. Install Thunderbird for Windows on a Windows computer or via Wine in Linux.
  2. Get, and install ImportExport Tools for Thunderbird plugin.
  3. Import Outlook Express .dbx files into Thunderbird.
  4. Using the above plugin, export to mbox.
  5. Import mbox mail archive into Apple Mail on OS X.

While going through my archived CD-ROMs earlier this week, I stumbled upon my old email backups. Interested in looking for a way to read this archive, I spent the next half hour scouring the internet for ways to convert these binary files ending with .dbx to the universal (and client-friendly) email format: mbox. I found none that I could use right away, most of the offerings being one form of commercial converter or the other.

Changing tack, I first tried importing it into Outlook on my work laptop that currently runs Windows 7, hoping it would recognize and allow me to import from it’s ugly sibling. It apparently looked for a specific location for these Outlook Express files, and the import eventually failed when it did not find the pre-designated path. (I do not know what that is, because the error wasn’t descriptive enough to try recreate this path so I could enforce the import).

Later that evening, over supper, I realized Thunderbird (for Windows) still had it within that it could import email from Outlook Express. I downloaded a copy on my work laptop, and installed it — despite limited user level privileges. To my luck, Thunderbird offered a way to import email from Outlook Express, and it read and pulled in all my old messages — pretty much flawlessly. Post import, I could merge inbox and sent message folders by copy-pasting all messages into one.

Next, I installed ImportExport Tools plugin on Thunderbird, which allowed me to export the merged folder into an mbox archive that Apple Mail could eventually read.

Scripting replies in Outlook (July 13, 2017)

Given my use of hot keys to expand text, it was time to take-on another task: scripting replies in Outlook. I have previously covered how to do this in Apple Mail, compared to which, the following is mouthy. There’s a good reason for that, which I’ll get-to in a minute. But it does the job.

Depending on the email service used, SenderName generates two types, viz.,

John Doe
Doe, John

The first name-type is common among personal email services. Whereas, enterprise email systems, like Microsoft Exchange, generate comma-separated name-types. Some organisations also append org-structures to first names. Here’s how mine looks. As you can see, filtering first name out of this complicates things.


The following script addresses all three above cases successfully:

; Scripting replies in Outlook 2016 with AutoHotkey
; Hit Ctrl + Win + r to create a reply email (template) 
; 2017 ckunte
ol := COMObjActive("Outlook.Application").ActiveExplorer.Selection.Item(1)
From := ol.SenderName
StringGetPos, pos, From, `,
if errorlevel
    StringGetPos, pos, From, %A_Space%
    StringLeft, From, From, pos
    StringTrimLeft, From, From, pos+2
StringUpper From, From, T
FirstName := RegExReplace(From, " .*", "") ; Removes all text trailing first name
SendInput, ^+r ; reply all (For reply to sender, but not all, use ^r)
Sleep, 100
SendInput, Hi %FirstName%, {Enter 2}Thank you for your email.{Enter 2}

Insert this snippet into the autohotkey (.ahk) file as an independent entry (i.e., separate by a line space at both ends), customise the last-but-one line to get your own way of addressing people, recompile using Ahk2Exe, run the thus generated .exe file (works as a systray app.), and then hit Ctrl + Win + r by selecting (or opening) a received email in Outlook, and you should see a reply-all window with the following pre-populated:

Hi <FirstName>,

Thank you for your email.

<Signature appears here, if set-up in Outlook>

The actual first name of the sender (to whose email you’d be replying to) will appear in lieu of <FirstName> in the example above.

Scripting replies in Outlook

For someone replying to tens of email messages a day, this is good automation — lots of keystrokes saved. My wrists and fingers aren’t complaining.