... wherein I bloviate discursively

Brian Clapper,

Append a random fortune to a signature

| Comments

I recently switched from Thunderbird to, on my MacBook Pro. For years, I’ve been appending random fortunes to the bottom of my email messages, and I wanted this feature for, too.

When I used Emacs’ VM to read mail, I merely had to hack together a tiny bit of Elisp and wire it into a VM hook.

When I moved to Thunderbird, I simply wrote a small shell script to concatenate a signature prefix file with a random fortune; I then told cron(8) to run that shell script once a minute, to create a new .signature file. I pointed Thunderbird at that generated .signature file.

But, as it turns out, you can’t point at an external .signature file, so the Thunderbird solution won’t work.

The answer is to write a small bit of AppleScript (one of the stranger programming languages I’ve ever used). The AppleScript script:

  • Uses the same signature prefix file that the Thunderbird shell script uses.
  • Concatenates the contents of that prefix file with the output from my fortune program.
  • Tells to replace the named signature. (I have more than one signature, and I only want to append a random fortune to one of them.)

Here’s the AppleScript code:

Add random fortune to signature Source Code
Liquid error: GET 403 - API rate limit exceeded for (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.) // See:

The final piece of the puzzle is another cron(8) entry, in my personal crontab:

* * * * * osascript $HOME/AppleScripts/fortune-sig.scpt

Conceptually, this solution is the same as the one for Thunderbird; it’s just a different implementation.