mark twain quote header image

Well, here it is: my last Geeklet post of 2011. I think it’s the simplest Geeklet I have, but it’s kind of fun. It uses the I ♥ Quotes API to put a random quote on your desktop.

Simpsons ChalkboardThere’s a variety of quote categories to choose from, ranging from geeky to humorous, religious to sci-fi. See the API page for a list and replace “literature” in the url with whatever you like. You can pull from multiple categories by separating them with a “+” in the url. There’s even a simpsons_chalkboard category to play with.

Here’s the one-line command that you can stick right into the Geeklet/Nerdlet without worrying about a shell script (Updated: I added some more awk fun to the end to rewrap the output while preserving the break before a “– Author” attribution):

curl -s 'http://www.iheartquotes.com/api/v1/random?max_lines=5&source=literature+macintosh'| \
grep -v "http://iheartquotes"| \
sed -e 's/\&/\&/g'|sed -e 's/"//g'| \
awk '{printf "%s ",$0} END {print ""}'|awk -F"--" -v OFS="\n\n" ' $1=$1'

You should remove the “" and newline at the end of each line (putting it all on one single line).

The first part (before the first pipe) just uses curl to grab a random quote from the “literature” section of the Quotes site (the -s makes it operate “silently” with no additional feedback). The url query parameters limit the quotes to a maximum of two five1 lines, just to maintain a somewhat consistent length and make it easier to set up fonts and styles. The result of the API call is sent to grep -v to remove the credit line at the end of the response, and then on to sed for a little typographic cleanup (replace quote entities and convert double hyphens to an em dash). The two awk statements at the end will first remove any line breaks, and then, if there’s a double-hyphen (which almost always means an attribution line in these API responses), it adds a double newline and converts that to an em dash2.

Have fun with it, and have a Happy New Year!

  1. I upped this from two to five because, with the new rewrapping I’m doing, I could fit a lot more text into a wider geeklet. 

  2. The only time this causes problems is when there’s a double-hyphen actually used as an em dash in the quote, which I’ve only had happen once so far.