Google Search Action for GNOME Do

Below, I create a simple Google search action by implementing the IAction interface from the Do.Addins library. I give the action a name, a description, and I use the stock “search” icon. I specify that this action only supports the ITextItem type, which is simply a type representing the text the user entered. In the Perform method, I assemble the URL for performing a Google search using the text from the first item (I know it’s an ITextItem because that’s all this action supports). Finally, I open that URL with a method provided by the Do.Addins.Util.Environment class.*
using System;
using Do.Addins;
using Do.Universe;
namespace GoogleAction
{
class GoogleAction : IAction
{
public string Name { get { return "Google"; } }
public string Description { get { return "Search Google."; } }
public string Icon { get { return "search"; } }
public Type[] SupportedItemTypes {
get { return new Type[] { typeof (ITextItem) }; }
}
public Type[] SupportedModifierItemTypes {
get { return null; }
}
public bool ModifierItemsOptional {
get { return false; }
}
public bool SupportsItem (IItem item) {
return true;
}
public bool SupportsModifierItemForItems (IItem[] items, IItem modItem) {
return false;
}
public IItem[] DynamicModifierItemsForItem (IItem item) {
return null;
}
public IItem[] Perform (IItem[] items, IItem[] modItems) {
string query;
query = "http://www.google.com/search?q=" + (items[0] as ITextItem).Text;
Util.Environment.Open (query);
return null;
}
}
}
Then, compile the plugin, install it, and restart GNOME Do:
$ gmcs -target:library -r:System -r:/usr/lib/do/Do.Addins GoogleAction.cs
$ mv GoogleAction.dll ~/.do/plugins
$ killall gnome-do
$ gnome-do
Get it? Got it? Good.
*Note: Real plugins should be more robust, do some error checking, have comments, etc. This is only a sample.
11 Comments
December 7th, 2007 at 10:49 am
I like how this works a lot. It seems more logical to type “Google blah”. Let’s say I want to send an IM to someone whose screen name is Gimp or something. Rather than having to type Gimp (in which case I would get either the GIMP or their name, I find it more logical to do “im gimp” for the IM and “gimp” for the program. Just my opinion obviously.
December 7th, 2007 at 11:10 am
This is very cool to know. I hadn’t realized that commands actually came up in the first pane. I thought only IItems could. This opens up some possibilities.
Thanks for taking a sec for this quick intro.
December 8th, 2007 at 8:57 am
Awesome. Thanks for spelling this out. I was able to make some simple changes to the template and search Wikipedia and my del.icio.us bookmarks. I tried to set this up for ubuntuforums.org but I’m not sure how to convert my text into their searchid.
I did have a little trouble getting this to work. I had installed Gnome-Do through Synaptic and I got a permission error when I ran gmcs. I removed it and then built from the trunk and it worked fine. Is this normal or is this a lack of understanding on my part?
December 8th, 2007 at 9:09 am
“I got a permission error when I ran gmcs” - weird. I have no idea what happened!
I suggest you make an abstract “WebSearchCommand” class, and then you could easily create new web search commands by subclassing it, and implementing a SearchURLWithQueryString method. This way you could create your Wikipedia, del.icio.us, etc commands in 5-10 lines each.
December 8th, 2007 at 2:00 pm
Huh, interesting, how come my gnome-do is rectangular boxed? instead of round boxed
December 8th, 2007 at 2:01 pm
Apologies, didn’t know I can’t put HTML in comments
Here’s a snapshot of my gnome-do, weird behavior indeed
http://img337.imageshack.us/my.php?image=gnomedoiu9.png
December 8th, 2007 at 2:22 pm
You need compositing turned on for the pretty window.
December 9th, 2007 at 8:43 am
The command to download and install at http://do.davebsd.com/?q=content/download has a typo. Either the && or the ; should be there, but not both. The line’s right on the launchpad page, wrong on http://do.davebsd.com/?q=content/download.
Nice little bit of software!
December 9th, 2007 at 12:42 pm
Using Gnome Do in Ubuntu Gutsy, that path for Do.Addins library is wrong. I have tha library just in “/usr/lib/do/”.
And works fine!
December 10th, 2007 at 11:17 am
Wow, it’s very easy make a addins for some web search with the GoogleCommand, making some little changes on the code I make a Youtube search videos with Gnome Do.
Very nice and easy.
Bye
January 15th, 2008 at 11:51 pm
[...] a simple command on the browser’s location bar. Do would be faster. And rather than build a Google Search plugin, a Yubnub extension would allow you to query Google, MSN, Wikipedia, or Yahoo. Or Amazon. Or eBay. [...]
Leave a Reply