Consistent I’m Feeling Lucky macro for Google

google-searchsearchsearch-engines

I'm making a little script with Autohotkey to quickly go to the first Google result of a search term.
My problem is, the only method I've found for doing this though the URL is acting a little inconsistent.

http://www.google.com/search?q=searchterm&btnI=745

This only works when the first hit is deemed to be a very good match. Otherwise Google shows the normal 10 results.
However, the actual "I'm Feeling Lucky" button on their front pages always takes you to the first result.

Try these links:

http://www.google.com/search?q=new%20york&btnI=745          <- works
http://www.google.com/search?q=new%20york%20dijon&btnI=745  <- doesn't work

"new york dijon" on the front-page and then hitting "I'm Feeling Lucky" does work though.

Any idea how I can get it to consistently work in URL form?

Edit: Okay, seems this might not be doable in a single URL. I'll mark a greasemonkey-script workaround as correct if posted.

Best Answer

Made a workaround Greasemonkey script:

// ==UserScript==
// @name         Google IFL
// @match        https://*.google.com/*?lucky=*
// @match        http://*.google.com/*?lucky=*
// ==/UserScript==

document.getElementById("gsr").style.display = 'none'; // optional. shows blank screen before forwarding. just looks better imo.
document.getElementById("gbqfq").focus();
var pathname = document.URL;
var start = pathname.indexOf("?lucky=");
var searchterm = pathname.substring(start+7);
document.getElementById("gbqfq").value = decodeURI(searchterm);
var btnLucky = document.getElementsByName('btnI')[0];
btnLucky.click();

This script will always forward you to Google's "I Feel Lucky" choice provided you navigate to www.google.com/?lucky=searchterm_goes_here.

I'm using it in FireFox by having a keyword to a bookmark going to www.google.com/?lucky=%s.

Related Question