Field Notes from the Workshop · № 023 Open Source

Ubiquity!

Joshua Doodnauth Software Engineer · Toronto
September 11, 2008 3 min read 627 words

This week I was introduced to Ubiquity, a very cool Firefox extension currently in the alpha release.  By cool, i mean that this little app potentially has the ability to bring together and combine the most relevent parts of the Web for you and your needs.  Currently there seems to be about 20 commands built-in to the current build, however there are a ton more which have been created by other users. Once the extension has been installed (which can be found here), pressing <CTRL>+<SPACE> will activate Ubiquity.  You don’t even need to know any commands to start, by typing a search term will instantly hit you back with results from Google, scrolling down will give you results from Wikipedia, IMDB, and Yahoo.  Highlighting and address on a Web page, and typing the command ‘map’ in Ubiquity, will return a fully interactive map from Google Maps, with the option to directly insert that map into an email or webpage.

Key to the development of the extension, is how incredibly easy it is to get started in creating new commands, it took me about 30-45 minutes to get through the Author Tutorial, and another 6 minutes to watch the introduction video.

After writing the ‘Hello-world’ program in the tutorial and going through the code of the examples, I was stuck, I didn’t know what command I could create.  So I decided to check my Gmail for any messages I may have neglected to read, but wait, there is a “Search Mail” button at the top, I could create a command to search my Email!

CmdUtils.CreateCommand({
name: “inbox-search”,
author: {name:”Joshua Doodnauth”},
licence: “GPL”,
description: “Searches the Users Gmail Inbox”,
help: “User must be logged on”,
takes: {“inbox-search”: noun_arb_text},
preview: function(pblock, theSearch) {
pblock.innerHTML = “Gmail Search: ” + theSearch.text;
},
execute: function( theSearch ) {
Utils.openUrlInBrowser(“http://mail.google.com/mail/?hl=en&shva=1#search/”+theSearch.text);
}
})

SIMPLE! Basically the ‘takes:’ function tells the user how to activate the command, the ‘preview:’ function will show how the command takes its input, and depending on what your it may return some result from the input command. The ‘execute’ function is where you run your command, which will usually execute in a new window.  All I did is use ‘inbox-search’ to activate the command, take the user’s input after the command as the search term, and inject it into the Gmail Search URL.  The only problem, is that obviosly the user will need a Gmail account, and will have to be logged in at the time.  In light of the login problem, I took the same idea of searching to somewhere the user doesn’t need an account, Google Image Search.

CmdUtils.CreateCommand({
name: “image-search”,
author: {name:”Joshua Doodnauth”, email:”jsdoodnauth@gmail.com”},
licence: “GPL”,
description: “Searches for images on Google”,
takes: {“image-search”: noun_arb_text},
preview: function(pblock, imSearch) {
pblock.innerHTML = “Google Image Search: ” + imSearch.text +” <br /><img src=’http://www.google.ca/intl/en_ALL/images/images_hp.gif’ width=’150′ />”;
},
execute: function(imSearch) {
var URL = “http://images.google.ca/images?gbv=2&hl=en&safe=on&q={QUERY}&btnG=Search+Images”;
var query = imSearch.text;
var searchStr = URL.replace(“{QUERY}”,query);
Utils.openUrlInBrowser(searchStr);
}
})

Almost identical, in the execute function I separated the search query from being directly inserted into the URL, and put the query into a variable. What I really wanted, was to return a preview of 5-8 images, but I need to find someone who can help me.  So for now I just put up the Google Image Search logo.

Ubiquity is a great extension, with many possibilities, and I will definiately keep my eye on where this project is going