Monthly Archives: September 2008

Playing with Ubiquity

Mozilla’s Ubiquity seems like a fairly neat idea.  It has its rough edges and glitches, but the idea seems promising.  I decided to give it a shot, and make a command to lookup bus routes here in Seattle.

CmdUtils.CreateCommand({
    name: "bus-schedule",
    takes: {"route": noun_arb_text},
    icon: "http://transit.metrokc.gov/favicon.ico",
    homepage: "https://endofline.wordpress.com",
    author: {name: "Adam Sanderson", email: "netghost@gmail.com"},
    license: "MPL",
    description: "Look up King County Metro bus route",
    help: "Select a bus route",

    _url: function(directObject){
      var url = "http://transit.metrokc.gov/cftemplates/show_schedule.cfm?BUS_ROUTE={QUERY}"
      var urlString = url.replace("{QUERY}", directObject.text);
      return urlString;
    },

    execute: function(directObject){
        var urlString = this._url(directObject);
        Utils.openUrlInBrowser(urlString);
    },

    preview: function(pblock, directObject){
        searchText = jQuery.trim(directObject.text);
        if(searchText.length <= 0) {
          pblock.innerHTML = "Look up King County Metro bus route";
        } else {
          jQuery.get( this._url(directObject), function(res) {
            var previewTemplate = "Look up route ${query} (${ok})";
            var ok = !res.match("No Schedule") ? "<em>Found</em>" : "<em> Not Found</em>";
            var previewData = {query: searchText, ok: ok};
            pblock.innerHTML = CmdUtils.renderTemplate(previewTemplate, previewData);
          });
        }
    }
});

One thing I really like about Ubiquity is that you can get a fairly rich preview.  This command for instance lets you know if the bus route you’re looking for is listed, not rocket science, but handy all the same.  For a nicely formatted version of this command, or to install it, check out the gist.

One thing left me a little puzzled about Ubiquity, why another text interface?  We already have the url bar, couldn’t Ubiquity launch from there?

1 Comment

Filed under Uncategorized