Skip to content

Instantly share code, notes, and snippets.

@brentsimmons
Created August 1, 2012 04:32
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentsimmons/3223686 to your computer and use it in GitHub Desktop.
Save brentsimmons/3223686 to your computer and use it in GitHub Desktop.
A script that generates a Google search URL and pastes it to the Mac OS X clipboard
#!/usr/bin/python
import sys
import os
from urllib import urlencode
import subprocess
# setClipboardData is from <http://www.macdrifter.com/2011/12/python-and-the-mac-clipboard/>*/
def setClipboardData(data):
p = subprocess.Popen(['pbcopy'], stdin=subprocess.PIPE)
p.stdin.write(data)
p.stdin.close()
searchString = " ".join(sys.argv[1:])
searchString = "http://www.google.com/search?" + urlencode({'q':searchString})
setClipboardData(searchString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment