• Home
  • Docs
  • About
  • Resume
  • Services
    • Testimonials
    • Leave A Testimonial
  • Stack Exchange
    • Android
      • Spanish
      • French
      • German
    • Apple
      • Spanish
      • French
      • German
    • Ask Ubuntu
      • Spanish
      • French
      • German
    • Bicycles
      • Spanish
      • French
      • German
    • Cooking
      • Spanish
      • French
      • German
    • CrossValidated
      • Spanish
      • French
      • German
    • Database Administrator
      • Spanish
      • French
      • German
    • Drupal
      • Spanish
      • French
      • German
    • Electronics
      • Spanish
      • French
      • German
    • Game Development
      • Spanish
      • French
      • German
    • Gaming
      • Spanish
      • French
      • German
    • GIS
      • Spanish
      • French
      • German
    • Home Improvement
      • Spanish
      • French
      • German
    • Mathematics
      • Spanish
      • French
      • German
    • Photography
      • Spanish
      • French
      • German
    • Physics
      • Spanish
      • French
      • German
    • Programmers
      • Spanish
      • French
      • German
    • Stack Overflow
      • Spanish
      • French
      • German
Humbug
Bah! Humbug!
Home 2010 Highlight and Search – Google Search from Any Ubuntu Linux Application
  • Email
  • Share

Highlight and Search – Google Search from Any Ubuntu Linux Application

  • Leave a comment
  • Tweet
Pratik Sinha | July 24, 2010

Some time ago, I wrote a post to show how to modify terminator to enable easy google searching. However I have trumped myself and have an even better solution now. Google Search from any application. Modus Operandi is: Highlight Text => Press Key Combination => Script picks up the query from the clipboard => Formats the query and opens the URL in your defualt browser.

Lets start with the script. Copy-Paste the below code into a file (Lets name it google_search).

#!/bin/bash
QUERY=`xclip -o | tr ' ' '+'`  #sanitize the query, change spaces to the plus sign
QUERY='"'$QUERY'"'    #put quotes around the query, exact search

if [ -x ~/bin/open_browser.sh ]; then
  open_browser.sh http://www.google.com/webhp?hl=en#hl=en\&q=$QUERY
else
  x-www-browser http://www.google.com/webhp?hl=en#hl=en\&q=$QUERY
fi

Copy the file to the bin directory under your home directory. Make the script executable.

cp google_search ~/bin
chmod +x ~/bin/google_search

Now lets take care of a few dependencies.

Install xclip. This utility is used to interact with the clipboard.

sudo aptitude install xclip

Update x-www-browser. See this tutorial for more instructions.

sudo update-alternatives --config x-www-browser

Now lets create a keyboard shortcut for the script we saved earlier.

Tutorial for KDE Users
Tutorial for Gnome Users

Thats it. Now you can highlight any text and press the keyboard shortcut you created in the last step and a google search for the selected phrase will open up in your default browser.

This script also supports the open_browser.sh script. Look here for more info.
When you press the keyboard combination, the browser may or may not become the active window. That depends on the focus model. However if you check your browser, the google search should be open in a new tab

Posted in Tips-N-Tricks | Tagged google search, Ubuntu | Leave a response

  • Tweet

Logging In...

Reply Click here to cancel reply.

Sign in with Twitter Sign in with Facebook
or

« Previous Next »

Recommend on Google
  • RSS
  • Facebook
  • Twitter

Subscribe

Get the latest posts delivered straight to your inbox.

Chatter Away

Recently Popular

  • Make English the Default Language for Google Chrome Search
  • Kill/Quit and Restart Plasma on KDE
  • Parse Simple XML Files using Bash – Extract Name Value Pairs and Attributes
  • Bash Tricks: Split / Cut a String with Multi Character Delimiters
  • Utility to Send Commands or Data to Other Terminals (tty/pts)
  • Make English the Default Language for Mozilla Firefox Search
  • A Sample Loop in XSL, Alternative for While, For Loops
  • Bash Tricks: Split / Cut a String with Multi Character Delimiters Using AWK
  • Bash Tricks: Create variables dynamically using some eval magic
  • Makefile Tricks: Arithmetic – Addition, Subtraction, Multiplication, Division, Modulo, Comparison

Latest Tweets

  • Ruby on Rails Debugging Techniques: Nice succinct blog on ROR debugging techniques, saving it for future reference... http://t.co/36mceCNP 2 hours ago
  • Get Android Remote Notifier to work with Unity on Ubuntu Natty (11.04) and Oneiric (11.10): Ubuntu Natty onwards, ... http://t.co/c3rLfD27 3 days ago
  • Wireless Sniffer on Ubuntu Linux - Capture / Analyze Network Traffic: Jotting down an easy recipe to get a 802.11 ... http://t.co/rZqwjVE5 1 week ago
  • RT @MaheshNBhatt: Mukul Sinha from Jansangharsh Manch called to say that the police are denying the riot victims the permission to hold ... 4 months ago
  • RT @MaheshNBhatt: They have just informed me that they will court arrest and begin to fast if the Gujarat govt denies them their constit ... 4 months ago

Services Offered

  • Embedded Linux Systems and Services
  • Gateway Routers (Frontend and Backend)
  • Free and Open Source Software Solutions
  • Network Monitoring Solutions
  • Device Driver Development

Recent Comments

  • buckley commented on Utility to Send Commands or Data to Other Terminals (tty/pts)
    (1 weeks ago)
  • Arup Kumar Kabi commented on Wireless Sniffer on Ubuntu Linux - Capture / Analyze Network Traffic
    (1 weeks ago)
  • Varun V Nair commented on Wireless Sniffer on Ubuntu Linux - Capture / Analyze Network Traffic
    (1 weeks ago)
  • Ajit Bhat commented on Wireless Sniffer on Ubuntu Linux - Capture / Analyze Network Traffic
    (1 weeks ago)

Categories

  • As An Aside
  • Code-Snippets
  • Software
  • Testimonials
  • Tips-N-Tricks

Copyright © 2012 Humbug.

Powered by WordPress and Hybrid.