The Plenitude of Arboreal Beauty

The author published this entry on Friday 07 December, 2007 at 10:11 am. It's been filed in the GNOME Docategory

Google Search Action for GNOME Do

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.

The Buzz {1 trackbacks/pingbacks}

  1. Pingback: tecosystems » Do or Do Not Do, There is No OS X on January 15, 2008

The Conversation {10 comments}

  1. nate 07 December, 07 @ 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.

  2. Rick 07 December, 07 @ 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.

  3. immensewok 08 December, 07 @ 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?

  4. Dave 08 December, 07 @ 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.

  5. Bo 08 December, 07 @ 2:00 pm

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

  6. Bo 08 December, 07 @ 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

  7. Dave 08 December, 07 @ 2:22 pm

    You need compositing turned on for the pretty window.

  8. Peter 09 December, 07 @ 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!

  9. Guillermo 09 December, 07 @ 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! :)

  10. ygallardo 10 December, 07 @ 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

Leave Your Own Comment

You can follow any responses to this entry via its RSS comments feed. You can also leave a trackback if the inclination is there.

If you're looking for something specific then give the search form below a try:

RSS Wordpress Grady (theme) Valid XHTML Return to the Top ↑