MacOS – Is Yosemite Mail caching signature files? How to get around that

macosmail.appsignature

I created a little script that looks up a random signature from an ever-growing list of quotes I have and modifies the HTML of my signature file to insert the quote into place. I trigger this script via launchd every few minutes so that my signature is 'randomized' throughout the day.

Up to Mavericks, this worked fine. Now, in Yosemite (10.10), the signature no longer gets updated. If I go into Prefs -> Signatures and drag/drop the signature from the 'All' list on to my mail account again it will trigger it to update. It also updates when I restart Mail. It appears that Mail is now caching the contents of the signature file and only refreshes it when it gets 'triggered' to in some way.

I know that there are now two possible copies of the signature file – a local and iCloud version. I've updated my script to make sure both are using the updated signature. If I restart mail or do the prefs trick, it does show the updated quote in the signature, so I know my script is running properly.

Does anyone know anything about this cache and/or how I might trigger Mail to refresh the signature with my script or some other trickery? I'm not even sure where to start looking for this sort of thing.

Best Answer

I had the same problem as you. I did some digging around and found a solution that used to work back in the OSX 10.8 days and stopped working with OSX 10.9. Oddly enough, it works again with OSX 10.10.1 and Mail 8.1 (1993).

There are multiple parts to this - an AppleScript that you compile into an Application, a text file containing your random quotes, two signatures in Mail.app (one is a template, the other is the actual signature for your messages), and the system 'cron' service. (Ideally you should use launchd, but I haven't got that far yet.)

The AppleScript:

if application "Mail" is running then
    set AppleScript's text item delimiters to "~###~"
    set myQuote to some text item of (read "/Users/Steve/.sigs.in")
    tell application "Mail"
       set the content of signature "MySignature" to the content of signature "MyTemplate" & myQuote
    end tell
end if

In my implementation (which you can deduce from the AppleScript):

  • My two Mail.app signatures are called "MyTemplate" and "MySignature". "MyTemplate" contains everything that is static - stuff like my email address, etc. "MySignature" is the one that I use with my messages.

  • The text file holding my quotes is called ".sigs.in" (so that it doesn't appear in Finder windows) and all the quotes are separated by a line holding only "~###~". This file lives in my home directory.

  • My crontab entry consists of

    * * * * * /Users/Steve/bin/MailRandomSig.app/Contents/MacOS/applet 

The compiled AppleScript lives in /Users/Steve/bin (obviously enough), and the "applet" part is the actual compiled binary that we want to run.

I've tested this and it works beautifully. Each minute, cron kicks off my compiled script which updates the signature.

The only "downside" is that if you don't like the quote you have to wait a minute for the script to refresh the signature and then reselect the signature from the drop-down selector in the message composition window. (I have two signatures - one static, the other the output of my script - to get around this.)