30 Jan 2009
Trigger Google search from command line script
I did actually write one small Python script, which I probably use a dozen times a day. It lets me trigger a Google search from the command line.
In Terminal I just type something like gs bacon
or gs 'shakespeare globe'
. The search results page then opens in my browser.
Here’s the very simple script:
#!/usr/bin/python
import sys
import os
from urllib import urlencode
os.system("open " + "http://www.google.com/search?" + urlencode({'q':sys.argv[1]}))
(Note: the last line that begins with os.system
should be all just one line.)