Automate subject in Apple's Mail.app

0

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]?

vzwick

Posted 2012-02-09T01:11:52.010

Reputation: 1 227

1That's not too easy (like, triggering automatically). I'd say it's pretty easy though to set up an Automator action that allows you to pre-populate a "new message" field. Would that be working for you? – slhck – 2012-02-09T08:17:15.470

What happens when the client gets rid of this junk when replying to that email? – Daniel Beck – 2012-02-09T08:28:53.597

1What I meant to say is, wouldn't it be better if you just created Smart Folders, one per client, and used the To/From email address as criterion? – Daniel Beck – 2012-02-09T13:04:42.033

Answers

2

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.

Karolos

Posted 2012-02-09T01:11:52.010

Reputation: 2 304

I'd move the display dialog to the first line. That way, the user can still cancel without mail being focused, Spaces being switched, and the new mail window created. – Daniel Beck – 2012-02-09T12:19:42.433

@DanielBeck: Good point. Edited. – Karolos – 2012-02-09T12:23:11.517