Generate Random Quotes with a Shell Script [Part 3/3: Integrate with Evolution Email]

This is the last part of the “Generate Random Quotes with a Shell Script” series of posts where we looked at 1) setting up user defined/specified quotes and 2) getting quotes from an online source such as quotationspage.com. For this post, I’ll walk you step-by-step on how to integrate an online source of quotes into a signature in the Evolution email client. Let’s get started…

First, we start off with the same script as mentioned in part 2, but this time, we clean it up a little bit and introduce HTML code for proper display. Here’s an example of what the final script should look like:


        rand_online=$[ ( $RANDOM % $num_online_quotes ) + 1 ]
        # In HTML source, <dt> is unique to quote and </dd> is unique to author
        # The field separators (FS) are either < or > which is [<>] in posix
        # TODO: Wanted to print as "quote -- author n (mini-bio)", but MacOSX 'fmt' is blah
        quote=$(wget -q -O - "http://www.quotationspage.com/quote/$rand_online.html" |
         grep -e "<dt>" -e "</dd>" | awk -F'[<>]' '{
                if($2 ~ /dt/)
                { print $3 }
                else if($4 ~ /b/)
                { print "-- " $7 "  n(" $19 ")"}

# 5 Attempts at obtaining a quote.  Silently fail.
while [ $i -lt 5 ]
        echo "$quote" | grep ERROR > /dev/null
        if [ $? -eq 0 ]
                i=`expr $i + 1`
                echo "<br /><br />"
                echo "<p>Best Regards,<br />"
                echo "<br />"
                echo "Derek Hildreth<br />"
                echo "--------------------------------------------------------------------------------<br />"
                echo "Embedded Systems Engineer <br />"
                echo "Technologic Systems<br />"
                echo "(480) 837-5200<br />"
                echo "<br />"
                echo "Random Quotationspage.com Quote:<br />"
                echo "$quote" | fmt -80
                echo "<br />"
                echo "--------------------------------------------------------------------------------</p>"

Then, we save the script with a descriptive name like random_quote_signature and then copy it to a location that makes sense — in the ~/.evolution/signatures directory.

cp random_quote_signature ~/.evolution/signatures/

Then, we start the process of adding it to the signatures list in Evolution. If you haven’t already done so, open Evolution and then start following the steps below:
Step 1:
Navigate to and select Edit -> Preferences

Step 2:
On the left hand side of the preferences window, select Composer Preferences, then select the Signatures tab and finally click on the Add Script button.

Step 3:
Give the signature a descriptive name like “Random Quote Signature” and click on the Script button. From here, drill down to the location of the script (ie. home/username/.evolution/signatures/random_quote_signature) and select it. You will get to see a preview of your script before using it in an email.

Step 4:
You can now test it by starting to compose a new message. Click on the “Signature” field button and select the newly created “Random Quote Signature”. It will automatically be inserted into your post.

And that’s it! Have fun with your new signature.

I hope you enjoyed the ideas and thoughts in this series of posts. They weren’t created to introduce anything ground-breaking or new and there were some other ways of accomplishing a very similar result (ie. fortune), but the goal was to introduce some scripting examples and their applications to something we use everyday. If you have any thoughts, comments, suggestions, or improvements I’d love to hear about them!

Feel free to donate if this post prevented any headaches! Another way to show your appreciation is to take a gander at these relative ads that you may be interested in:

There's 0 Comment So Far

Share your thoughts, leave a comment!