17 October 2007

OpenSearch plugin for Firefox

This is funny. I'm not sure what came first: the chicken or the egg. I'm also not sure which of these came first: me running into this page about creating search plugins for Firefox or my idea to create one for FreshPorts.

Anyway, the idea percolated around for a while. I finally got around to doing it. It was just a little more trouble than I expected, but not too bad. It helped to look at some third-party search plugins that I already had installed. We'll need to find where that directory is anyway. (BTW, this subdirectory won't exist yet if you've never before installed an additional search plugin.) On Unix it's usually something like "$HOME/.mozilla/firefox/*.default/searchplugins/" where "$HOME" is your home directory and "*.default" represents the random looking text along with ".default" that Firefox uses for that directory name. (In Windows, it will be in something like "C:\Documents and Settings\username\Application Data\Mozilla\Firefox\Profiles\*.default\searchplugins\". And on Mac OSX, try "/Users/username/Library/Application Support/Firefox/Profiles/*.default/searchplugins/". (Change "username" to your user name.))

As long as you've installed an add-on search plugin, there should be at least one file in the "searchplugins" directory with a suffix of ".xml". If you look at the contents of that file, you can see a real world example of what we're trying to do for FreshPorts.

So, basically, it's a big game of fill-in-the-blanks. I'll spare you the details of all my starts and stops, and get right to the good stuff. The below is what I ended up with. If you put it into a file named "freshports.xml" in your "searchplugins" directory and then start (or restart) Firefox, you can search FreshPorts straight from the browser's little search box in the navigation tool bar. It even has a nice little daemon picture.

<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/"
xmlns:moz="http://www.mozilla.org/2006/browser/search/">
<ShortName>FreshPorts</ShortName>
<Description>Everything you want to know about FreeBSD software, ports, packages, and applications.</Description>
<InputEncoding>UTF-8</InputEncoding>
<Image width="16" height="16">data:image/x-icon;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAACTElEQVR42oWSTUjTcRjHP/85pw7bnHPOXOkWJlK6LfEk6EqxQ1l4MDp0iMqKqFOX6GDooeiNAqkOlUhERWjZq5WRZlBJk/7FUgvZ1BA1nKhbM910v05Z1lzf2wPf58vneYElNDA4KP6s7zU2C9kpi799ykjN1y9eFZODQwuNPq8Xb/8A7afP4Xr/QeTl26Vf3phIAX73UI1meJgCW0FN/bGTKL+NoA+FiA3OYtAso6HlUW1UAsfWLdSfrSNJr8Fq1HGw+jCJBet491qGZN0iryJSQPWZWqlk7w7G5kMABINz3OxwcfR4HT3PX/4/AGDz9koAvLOzdF5qYPzWDay93Yw2NSM7ZTHh8wsAiSg6su+QeNZ4F7NSRaoQJFgyKK7ahXtyAkfZRrKzzEsTAJy6fEFakWogIATD+iRsVTvpetxKvErDmN/Pj+/jRJXslEWFwSz2pK0SJ9IswpqWKcpSMkVfz+eFf4hKMD46gidG8HVunkmfH7vZQvXta6xek7MwujJagEqtBmBIEWYsTsUBu43i0vWL9haV4E3HKwLT08QqFGQikbXO9o8nIoHslIWrq4vWlqcs15sIh2cIaNX0T00hO2VhNOlITzdLi874qdsl2lo76fV0M/LFjS4lGYC+tx9J8E8Qzs7HXl5KUCiITzHhyDFQ7iiUJI/bI5qamnlx5wHbKitQz4WY0SfTeP8hPb19qLVGALSZVoo2lbDBtpIMo5Fci+k3Qd35K6Kt/QmJQiJLq6OoqJDS/bslj9sjAlM+pLgYctfmRXy6n7Ci4m2PovV/AAAAAElFTkSuQmCC</Image>
<Url type="text/html" method="GET" template="http://www.freshports.org/search.php?query={searchTerms}" />
<Url type="application/x-suggestions+json" template="http://www.freshports.org/faq.php"/>
<moz:SearchForm>http://www.freshports.org/search.php</moz:SearchForm>
</OpenSearchDescription>


(There's going to be some serious line wrapping there. I'm thinking that reading the details of each line right here is less important than having a clean cut-and-paste chunk.)

I'm finding this very useful. I use FreshPorts often to see what's in the latest ports tree, because I don't update my own ports tree every day. (See here if you're curious why.) Going straight to search results saves a lot of time and unneeded page loads.

So, here's the funny part. After I finished all of this, I was so pleased with myself that I just couldn't wait to post it on some mozilla/Firefox site for the rest of the world to enjoy. It seems the right site for that is the Mycroft Project. Well, ... of course, there was a FreshPorts search plugin there already. If you just go to the Mycroft site and type "freshports" in their search box it takes you right to it -- and you can install it with just a couple of clicks. ... Of course, it would make me feel a lot better if you'd cut and paste and use mine. But, I'll understand if you don't.

A small note

The base64 representation of the daemon icon I got out of the "URI Kitchen" (linked from the "Creating OpenSearch Plugins ..." page) was really large. It worked just fine, but was giant. In my version above, therefore, I used the same thing for the image data as the other plugin.

Labels: ,

0 Comments:

Post a Comment

<< Home