Automatically Prepare Email (Mail, OS X): Sender, Recipient, GPG Encryption Checked
Sometimes, I enjoy doing something that does not belong to my core area of expertise, at first glance. Still it is fun to figure out how something works 😉
Here is the “problem” I decided to address: – frequently, I send emails to “recipient_x_”. – The content of these messages should be encoded via pgp. I use gpg tools, which I like because their seamless integration into apple mail. Depsite this seamlessness, I have to click on a button to tell mail to encrypt the message, every time I want to send an email. Granted, I could encrypt by default, but among my typical recipients, the ones that use pgp are in the minority. And yes, I am still using apple mail, despite some interesting new kids on the block (MailMate at the forefront). I do use the add-ons mail tags and mail act on though. – I want to send this email from a particular email account
These tasks seems to be ideal for automation, I must have captured the macpowerusers bug. Typically I do most of my scripting with python. I dislike solutions that are bound to something specific like a given operating system. Despite recent discussions about the state of the mac, I don’t foresee myself to be using anything else in the near future. Hence, I started looking into automator, which has a few mail related tasks available, such as selecting the account. However, it has no way to automate gpg.
The next step was to look into applescript. I’ve looked a bit into it in the past, when I created latex based pdfs as notes for omni outliner. Generally, an applescript can be associated with a keyboard shortcut. Keyboard maestro, which I own since a little while, offers similar functionality, with improved user-friendliness. So now, when I am in mail, I just have to type cmd - opt - E
, the script is executed, and I get a window as shown below. The three areas highlighted by red rectangles are adapted according to variables in the script.
Feel free to check out my script on github.