MoD Email Subjects with AppleScript
The work I do with the RAF and Army requires me to send emails with the date and security classification included, like this: “20130628-The Subject-U”.

I must do this at least 30 times a day, and earlier on I was that fed up with copy/pasting dates that I decided to write a script to do it for me. I did try this once before, but Mail.app’s API wasn’t very robust at the time and the action relied upon simulating keypresses which wasn’t exactly reliable.
The following script adds the date and PM to the subject of the foremost Compose Mail Window. It’s a little smarter than my previous attempt too, in that it replaces the date if it’s already there and leaves the PM alone if it exists already.
This one opens a reply to the selected message, with the “Re:” in the right place:
Using Applescript is awkward to say the least - Russell Beattie puts it quite well:
Using AppleScript is like being tied down in a black leather gimp-suit at a dominatrix convention, and losing the safety word… The syntax is like Erlang and ancient Greek got somehow mixed together with Visual Basic, and was translated back into English by mentally-challenged ESL students
I did try to make a plugin for Mail.app to add some buttons to the menubar, but after discovering how difficult it is working with Mail.app’s undocumented API, I gave up and created a Service instead.
Despite AppleScript’s quirks, it’s still the most reliable way to automate Mac applications, especially when you need to interact with specific UI elements like email compose windows.