Saturday, July 16, 2005

OK we've got pipes! How to combine YubNub commands together.

Alright, we now have a way to chain commands together (but our work is not yet done, as I will explain in a moment).

For example, to see the Penny Arcade comic from a week ago, we can combine the paview and date commands as follows:

paview {date -format Y-m-d -offset -7}

Type that into YubNub and you will be taken to last week's Penny Arcade comic:

So to use the output of one command as the parameter for another, simply enclose the command in {curly brackets}.

And that's not all. If you find yourself often typing paview {date -format Y-m-d -offset -${age=7}}, you can make a new command for it. Just make a new command called paview2 with the following URL:

paview {date -format Y-m-d -offset -7}

No that is not a typo -- you type the same thing into the Create New Command box as you do into the YubNub command line. In other words, you can create new commands by combining existing ones together. So now you can type paview2 and it will take you to last week's Penny Arcade comic.

We can even make a paview3 command that is a bit more flexible. This third version will let you optionally specify the age of the Penny Arcade comic that you want, in days (see Advanced Syntax for more information on parameters and default values). Give paview3 the following URL:

paview {date -format Y-m-d -offset -${age=7}}

Now you can type paview3 to get last week's comic, or paview3 -age 20 to get the comic from 20 days ago, etc.

Note that this technique cannot be used to pass huge chunks of text between commands. This technique is used to pass small snippets of text, which is perfect for specifying parameters as in the examples above.

I said at the start of this post that our work is not yet done. We need more little commands (like echo, date, and url) that generate useful snippets of text that can be inserted into other commands. We also need a screen-scraper command to make it easier for people to make these little commands. Sean O'Hagan is working on a screen-scraper -- alternative implementations are also welcome.

I would like to acknowledge two people who have been doing R&D on combining commands together: Erik Kastner and Richard Frankel. I would also like to acknowledge the ideas of several individuals regarding syntax and implementation -- these include Bill Katz, Nick Fortune, Michael Pacchioli, Ciro Mondueri, Alex Ksikes (Alex has a ton of ideas) and more recently: Jeremy Hussell, Mathieu Balez, and Sean O'Hagan.


Anonymous Anonymous said...

Exciting times, we live in :D.
Great job with the "pipes," Jon. They're a bit more confusing than normal pipes, but we'll get used to them.

7/17/2005 8:32 a.m.  
Blogger Jonathan said...

Hi Tommy - Yeah, maybe we'll save "|" for if and when we pass big chunks of text (like full HTML or XML documents).

7/17/2005 12:13 p.m.  
Blogger Elaine said...

YubNub command today (with offset options to account for local difference from GMT) all set up.

Many thanks!

Now if i can figure out how to make firefox bookmark a keyword instead of a URL....

7/17/2005 2:05 p.m.  
Anonymous Anonymous said...

This is fantastic.

Jon, I may have to update that article before it hits 'the presses'. ;)


7/18/2005 2:12 p.m.  
Blogger Jonathan said...

Hmm ... IE turns ...

paview {date -format Y-m-d -offset -7}

... into ...{date%20-format%20Y-m-d%20-offset%20-7}

... whereas we really want ...

7/23/2005 3:20 p.m.  
Blogger Jonathan said...

Mat - Ha! (Mat writes magazine articles, among other things.)

Judie - Congrats on the timezone-smart command you made!

7/23/2005 3:37 p.m.  

Post a Comment

<< Home