Jacob Evans

How to Add a Little Inspiration to Your Email Signature

Speaking of email, I’ve been wanting to jazz up my email signature for some time because, ya know, email signatures are boring and very predictable. Until today, my default signature, outputted using a TextExpander snippet, contained a valedictory and just one other word: my first name. I thought it might be fun to add an inspirational quote at random to the bottom of my signature line, which now looks like this:

Example email with signature containing a random quote.

Here’s how I did it.

I recently created a spreadsheet of quotes for another project, and I thought it would be neat if I could create a script to consult the spreadsheet and output a formatted quote at random. Turns out, it wasn’t very hard to do just that with a little bit of AppleScript and TextExpander magic. Here’s the AppleScript:

property _quotes : missing value

  Get the list of quotes from a selected Apple Numbers file and cache
  the list of quotes in a property that will be used for subsiquent
  executions of this script.
  The list of quotes should be in a table on the first sheet of a 
  Numbers document with the quote in column "A" and the quote's author
  in column "B". The first sheet should only contain this one table.
if _quotes is equal to missing value then
  -- Get a reference to the current app that will be activated
  -- after the Numbers document is selected and it's content read.
  set _currApp to (path to frontmost application as Unicode text)
  tell application "Numbers"
    set _quotesDocPath to POSIX path of (choose file with prompt ¬
      "Quotes Spreadsheet Location:" default location ¬
      	(path to home folder))
    set _doc to open _quotesDocPath
    tell front document to tell active sheet
      tell (first table whose selection range's class is range) to ¬
        set _quotes to rows's cells's value
    end tell
    close _doc
  end tell
  tell application _currApp to activate
end if

-- Pick a quote from the list at random
set _quote to item (random number from 2 to count of _quotes) of _quotes

-- Format the quote and output the author's name in uppercase.
return "\"" & item 1 of _quote & "\" —" & (do shell script "echo " & (item 2 of _quote) & " | tr [:lower:] [:upper:]")

All I needed to do next was create a TextExpander snippet to run the script. Then add the newly created script snippet to the bottom of snippet responsible for outputting my signature. Here's screenshot depicting one of my signature snippets that includes the random quote snippet:

Example of my email signature snippet as it appears in TextExpander

Note: the first time the script runs, it prompts for the location of the Numbers spreadsheet containing the quotes to use. TextExpander may also need to be granted permission to read files located in the home folder.

I’m pleased to report this works quite well. The only catch is the TextExpander snippet needs to be changed slightly whenever the quotes spreadsheet is updated (for example, by adding a new line to the end of the script entry). This will cause it to reload and cache the updated quotes.

My Apple Numbers quotes spreadsheet can be downloaded from here.

Enjoy doling out little morsels of inspiration one email at a time!