Thursday 26 April 2018

macos - Automate subject in Apple's Mail.app


At the company I work with, we use [client-domain.com] prefixes before the actual subject line of emails as kind of a rough tagging system.


Is there any way that one could automate this so when I start writing a new email to johndoe@foobar.com, the subject will be pre-populated by [foobar.com]?



Answer



A quick and dirty AppleScript attempt to achieve what you want, but it certainly can be improved, i.e. being bound to Automator actions, based on selection from selected items in your address book.


To use this, open "AppleScript Editor" (it's in /Applications/Utilities/, or use Spotlight), paste the following as the text body and click "run". If it's OK, you can save the script and later run it by clicking on it.


   set recipientList to display dialog "Enter the email address:" default answer ""       
tell application "Mail"
set composeMessage to make new outgoing message at beginning with properties {visible:true}

tell composeMessage
set recipientList to (text returned of recipientList)
make new to recipient at end of to recipients with properties {address:recipientList}
set AppleScript's text item delimiters to "@"
set domain to text item 2 of recipientList
set subject to "[" & domain & "]"
end tell
end tell

Of course, this can be improved upon.


Also, you should know, as pointed out by Daniel Beck that the recipient is free to remove that field; it's best to rely on hidden mail headers. But given you already have the domain, this info is safely stored in the email recipient.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...