How do I search firefox Smart Search from the command line in OS X?
February 19, 2007 8:33 PM   Subscribe

I absolutely love Firefox Smart Keyword Searches. Beyond just the default preinstalled ones, I also use custom ones for easynews, rottentomatoes, metafilter, etc. Here's my question: Is it possible to launch these from the command line in OS X? For example, ideally I would enter (into a bash prompt) rt apple to open a new tab in firefox with a search result for "Apple" in rotten tomatoes, like this.. Similarly, I would like to be able to enter easy creative commons to have it launch the keyword bookmark "easy" which searches easynews global for "creative commons". Is this possible to do, preferably without using Applescript or Automator?
posted by crazyray to Computers & Internet (14 answers total) 10 users marked this as a favorite
I don't know about using the command line, but you can replicate the behavior in Safari using Sogudi.
posted by ardgedee at 8:44 PM on February 19, 2007

Not sure about the command line. You can do it with Quicksilver, though.
posted by danb at 9:00 PM on February 19, 2007

Second using Quicksilver.
posted by Blazecock Pileon at 9:09 PM on February 19, 2007

Not much to add here but just wanted to say that I use Quicksilver's Web Search Module and it has actually kind of changed my life. In my opinion it's better than doing it from the terminal because you don't have to switch windows. If you've never checked out Quicksilver you should definitely give it a look.
posted by subclub at 9:10 PM on February 19, 2007

Actually I have tried QuickSilver for several days not just once but two seperate times, and for some reason I just don't connect with it the way so many other people seem to.
posted by crazyray at 9:30 PM on February 19, 2007

Full disclosure; I haven't used a Mac since 1997, so I may be barking up the wrong tree, here. Therefore, I will restrict my answer to be relevant to Linux, and assume that Macs include Bash or something similar.

Anyway, in Linux, you could do a bash script like this. Make a file called "wiki". Put this in it:

firefox “$1″

then do

chmod +x wiki

In your terminal, to make the file executable, then move it to your /usr/bin folder (ie. where executable files are kept).

Henceforth, typing:

wiki Vodka

At the terminal will open up a new Firefox window, loaded to the Wikipedia entry for Vodka. Rinse and repeat for the other searches you want to do. Not very helpful, maybe, but doing this will require some kind of script to be written if you're doing it from the terminal.
posted by Jimbob at 9:41 PM on February 19, 2007 [2 favorites]

The script for Rotten Tomatoes, by the way, would look a little like this:

firefox "$1"

posted by Jimbob at 9:44 PM on February 19, 2007

Jimbob, thank you so very much! Based on your idea, and the idea of avoiding problems with spaces, here is what I ended up with:

for this_query_term in $@
open "$url"

If I may ask one more little thing, will this approach work for all the others as well? i.e. what would ebay look like?
posted by crazyray at 10:28 PM on February 19, 2007

Visit the website and do a few searches. The URL pattern will become clear.
posted by Blazecock Pileon at 10:37 PM on February 19, 2007

Does anyone know how to do this in *one line* in quicksilver? I want to open quicksilver, and type "g foosball" to search google for 'foosball'. With the web search module you have to do "g", TAB, TAB, "foosball", ENTER -- due to the way you are chaining the commands together...
posted by rsanheim at 10:59 PM on February 19, 2007

crazyray, bash can do string substitutions in parameter expansions, which would let you get rid of the for this_query_term loop and the redundant "+" it adds to the end of your query string. Try running

echo ${args// /+}

with a few arguments, and you'll get the idea. The bash manpage has all the gory details in the "parameter expansion" section.

For a command shell, bash is actually a pretty useful string processing language.
posted by flabdablet at 1:30 AM on February 20, 2007

echo "search=$*"

works too.
posted by flabdablet at 1:37 AM on February 20, 2007

Hmm, it doesn't look like the other solutions above do URI escaping. If you use Bash and have Perl's URI::Escape module installed (or are willing to install it), you can define shell functions such as this in your .bashrc:

function goo { open "`perl -MURI::Escape -e \"print uri_escape(\\"$1\\")\"`&hl=en" ; }

You invoke this shell function like so:

[you@yourhost]$ goo "if (flag1 && flag2)"

(Note that the entire set of arguments is quoted.) The function generates URL's such as

and uses the OS X open command, which will open the URL in your default browser.
posted by harmfulray at 8:44 AM on February 20, 2007

Bash can do it without perl, though it's a bit of a stretch :-)

Save this as /usr/bin/goo and chmod +x it:


function chr {
    printf -v chr \\\\%o $1
    printf -v chr $chr

function asc {
    local arg="${1:0:1}"
    local -i upper=256
    local -i lower=0
        let asc=(upper+lower)/2
        chr $asc
        [ "$chr" == "$arg" ]
        if [ "$chr" '>' "$arg" ]
            let upper=asc
            let lower=asc

function url_escape {
    local c
    for ((i=0; i<${#1}; i++))
        [[ "$c" =~ '[-!$'\''()*+,.0-9A-Z_a-z]' ]] || {
            asc "$c"
            printf -v c %%%02X $asc

function google_search {
    url_escape "$1"
    open "$url_escape&hl=en"

google_search "$*"

Once you've done that,

goo penguin will generate
open "",

goo penguin cafe orchestra will get you
open "",

goo 'penguin cafe orchestra' runs
open "",

goo \"penguin cafe orchestra\" yields
open "", and

goo '"penguin cafe orchestra"' makes
open "".

Given the insane amount of fartarsing about required to do the character escaping, this runs surprisingly briskly - probably because it's all done with bash builtins and doesn't launch any external processes or subshells.

Here's a link to goo to save you copying and pasting possibly MeFi-mangled code.

If anybody can think of a faster way for bash to convert characters to numbers and back than the chr and asc functions presented here, I'd love to see it.
posted by flabdablet at 7:33 AM on February 21, 2007

« Older Some questions about fonts specified in a colophon   |   Photoshop: clean up newsprint background? Newer »
This thread is closed to new comments.