Feed Sign in with OpenID OpenID

Simon Willison’s Weblog

Abusing the command line

If you’re running OS X, try this:

say -v Kathy `curl --silent http://api.technorati.com/getinfo?username=simonwillison | grep ’<inbound’ | sed -e ’s/ <//’ | sed -e ’s/inboundblogs>/Simons blog has /’ | sed -e ’s/<\/inboundblogs>/ inbound blogs and /’ | sed -e ’s/inboundlinks>//’ | sed -e ’s/<\/inboundlinks>/ inbound links/’`

Your computer should read out to you my Technorati inbound blogs and inbound links, extracted from the Technorati web API. Parsing XML using sed is a nasty trick I picked up from this O’Reilly article; speaking the output of a command using the ’say’ and the backtick shell operator was my moment of inspiration for the day.

This is Abusing the command line by Simon Willison, posted on 26th March 2004.

View blog reactions

Next: Conferences with Macs

Previous: Quicksilver

7 comments

  1. I'm embarrassed to admit I just spent the last 10 minutes making my computer 'say' uh, bad things.

    Gina - 26th March 2004 02:56 - #

  2. Festival is good for that on Linux:

    $ festival --tts < file.txt

    Michael - 26th March 2004 04:09 - #

  3. or, on a linux system:

    Your comment could not be added:

    * XHTML is not well-formed

    oh well, i tried.

    Eric - 26th March 2004 05:41 - #

  4. You probably forgot to painstakingly escape every single ampersand, less-than and greater-than sign. Of course, it's absurd that you have to remember to do that. Time to make the comment system a bit less draconian.

    Simon Willison - 26th March 2004 06:46 - #

  5. You don't need all those sed commands. You can join them up into one big sed command with lots of -e flags. It'll run ever so slightly quicker. :-)

    Whilst it's a very cute one liner, I'm finding more and more that I would knock up a quick XSLT stylesheet to do jobs like this instead. It's a lot less brittle if you end up using it a lot. I would say that XSLT is hard, but compared to Unix shell scripting, there's probably not much in it! It doesn't have the "one liner" factor as much though.

    -Dom

    Dominic Mitchell - 26th March 2004 07:16 - #

  6. Ok, I couldn't resist. Here's a slightly condensed version.

    say -v Kathy `curl --silent "http://api.technorati.com/getinfo?username=simonw illison"  |
    sed '/<inbound/{s/ <//;
    s/inboundblogs>/Simons blog has /;
    s/<\/inboundblogs>/ inbound blogs and /;
    s/inboundlinks>//;
    s/<\/inboundlinks>/ inbound links/;}'`

    Dominic Mitchll - 26th March 2004 07:23 - #

  7. On Debian you can also use flite:

    echo 'hello' | flite

    Levin - 26th March 2004 11:48 - #

Comments are closed.

Previously hosted at http://simon.incutio.com/archive/2004/03/26/abusing

A django site