Append a new random quote to the end of a Mail signature

Apr 14, '10 07:30:00AM

Contributed by: Anonymous

Here's an AppleScript that will append a new random quote from a text file to some or all of your Mail.app signatures every minute, using crontab. I've included somewhat detailed instructions on how to set the whole thing up.

First put your favorite quotes in a MacRoman encoded text file (most modern editors use UTF8 as the default, so be sure to specify MacRoman instead) somewhere on your hard drive. The quotes should be separated from each other by one empty line. Here's a sample file:

«In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.»
(Douglas Adams)

«Nothing travels faster than the speed of light, with the possible exception of bad news, which obeys its own set of laws.»
(Douglas Adams)

«A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.»
(Douglas Adams)
Next, in Mail.app, create one or more signatures to use as templates. These are the signatures that are going to have the quotes appended to them. Then create the actual signatures and associate them to your accounts. Don't bother putting anything in the actual signatures, as the script is going to overwrite them.

Open AppleScript Editor, and copy/paste the following code into it. Change the name of the file and the name of the signatures to match your own configuration:

if application "Mail" is running then
  set AppleScript's text item delimiters to "\n\n"
  set myQuote to some text item of (read "/Users/xxxxxx/Documents/Quotes.txt")
  tell application "Mail"
    set the content of signature "Personal" to the content of signature "TemplatePerso" & myQuote
    set the content of signature "Professional" to the content of signature "TemplatePro" & myQuote
  end tell
end if
Save this as an Application somewhere on your hard drive. Finally, have cron execute the script every minute using osascript. You can do that either by using a GUI application like CronniX, or by typing crontab -e in a Terminal window. Here is what the crontab line should look like:

* * * * * osascript ~/Applications/Randomize\ Signature.app >/dev/null 2>&1

Enjoy!

[robg adds: Previous random signature hints for Mail: via Fink's fortune, pulled from the internet, and a simple one-account version. I have not tested any of these.]

Comments (11)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20100412075438131