The Plenitude of Arboreal Beauty

…a vague essence haunting the multiplicity of finite trees.

Google Search Action for GNOME Do

with 13 comments

Google search action in GNOME Do
As more people are using GNOME Do, I keep getting nagged about how GNOME Do doesn’t do this or that. This is exactly why GNOME Do has a plugin system for adding to the items and actions GNOME Do provides. For example, many people have said “Launchy/Quicksilver/Katapult/my mom has a Google search action, why doesn’t GNOME Do have one? This is a bug!” Well, even though documentation is sparse at the moment, here’s an example of how easy it is to create a Google 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.

Written by Dave

December 7th, 2007 at 10:11 am

Posted in GNOME Do

13 Responses to 'Google Search Action for GNOME Do'

Subscribe to comments with RSS or TrackBack to 'Google Search Action for GNOME Do'.

  1. 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.

    nate

    7 Dec 07 at 10:49 am

  2. 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.

    Rick

    7 Dec 07 at 11:10 am

  3. 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?

    immensewok

    8 Dec 07 at 8:57 am

  4. “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.

    Dave

    8 Dec 07 at 9:09 am

  5. Huh, interesting, how come my gnome-do is rectangular boxed? instead of round boxed :(

    Bo

    8 Dec 07 at 2:00 pm

  6. 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

    Bo

    8 Dec 07 at 2:01 pm

  7. You need compositing turned on for the pretty window.

    Dave

    8 Dec 07 at 2:22 pm

  8. 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!

    Peter

    9 Dec 07 at 8:43 am

  9. 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! :)

    Guillermo

    9 Dec 07 at 12:42 pm

  10. 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

    ygallardo

    10 Dec 07 at 11:17 am

  11. [...] 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. [...]

  12. Hi, I’m using DO 0.8.1. I have modified the code.
    following the above steps, I got

    ERROR: Could not read add-in file: /home/skumar/.local/share/gnome-do/plugins-0.8.1/GoogleSearch.dll

    On googling, found that we need resource addin.xml to be included so I did,

    $ gmcs -target:library -r:/usr/local/lib/gnome-do/Do.Universe.dll GoogleSearch.cs “/res:GoogleSearch.addin.xml”

    and started gnome-do

    it showed,

    Creating package Do.GoogleSearch_0.1.mpack
    Installing GoogleSearch v0.1

    But the plug-in is not found in the GNOME Do preferences.

    sathyz

    6 May 09 at 12:18 pm

  13. [...] lets start writing the plug-in, the simplest plug-in that I found on net is Google-Search. There are few changes required (we need to include .addin.xml for the plug-in and we should [...]

Leave a Reply