Random Lipsum for TextExpander

[Tweet : nvALT]

I hate it when I get an idea for something simple and end up spending an hour figuring out how to do it. I figured I’d make a post out of it to make myself feel better. It all started with my being disappointed that the Loripscream API wasn’t working. I did a little digging and found that had a not-well-publicized XML feed you can pull from. That’s where the fun began.

The XML from lipsum.com must be malformed, although I only say that because System Events would not parse it in AppleScript. I resorted to Bash scripting, and probably did a pretty kludgy job of it, but it works.

You can adjust the following script to return anything from 1 word to 20 paragraphs (or more) of random Lorem Ipsum. Just change the query values in the curl call: what (words, paras, or bytes), amount (self-explanatory, I hope) and the “start” parameter tells it whether or not to begin the line with “Lorem Ipsum dolor sit…” or make it completely random. I’m going with random.

Sure, you could use this from the shell and pipe it to pbcopy, but a TextExpander snippet seemed like just the thing. Just create a new snippet and set the type to “Shell Script.” Then, paste this code in, modifying as you see fit.


curl -s 'http://www.lipsum.com/feed/xml?amount=2&what=paras&start=0'| \
xpath '//lipsum' 2>/dev/null | \ 
sed -e 's/<lipsum>//' -e 's/<\/lipsum>//'| \
awk -F"\n" '{print $1"\n"}'

For whatever that’s worth…