Select text and send it to google search and google translate from shortcut

It seems possible (as I learned from a comment to this question made by user55822) to use a command in order to search a term on the web by using "keybinding" the way Aretha is used.

What the aforementioned user says is that

"you could search mouse selection anywhere by using an app like Artha, or by keybinding sh -c 'firefox "http://translate.google.com/#en/fr/$(xclip -o)"' (example given translate english into french)"

A lot of things are obscure for me here. I could use Artha or keybinding (as alternative), or both? How to do that in each case?

and

"The command I gave you will open google translate in Firefox with your mouse selection (text highlighted) as a query. Use sh -c 'firefox "https://www.google.com/search?q=$(xclip -o)"' if you want regular Google over Google translate. And obviously, that would work everywhere"

I do not know what to do with that formula. What should I do exactly? How to use it? In what application?


I will try to explain it...
the command sh -c 'firefox "https://www.google.com/search?q=$(xclip -o)"' will open firefox in www.google.com searching the words you have selected with your mouse.
To use it , you should install "xclip"

  1. Go to the terminal and type sudo apt-get install xclip
  2. Then you can create a script with the command, create a "new document" and named as "search-google.sh"
  3. Open the file with gedit and put these lines: enter image description here
  4. Save the file in your home eg: /home/user/search-google.sh
  5. Then change the permissions to make the script executable in the terminal type: chmod 764 /home/user/search-google.sh
  6. Then you can create a custom keyboard shortcut to execute the script.
  7. Go to System Settings > Keyboard > shortcuts > Custom Shorcuts enter image description here
  8. Add a new item and fill the fields Name:search-google and Command:sh/home/user/google-search.sh enter image description here
  9. Then give a keyboard shorcut to the script...click in "Disabled" and press the keys to the shortcut. eg: Ctrl+Alt+G enter image description here

  10. So, if you are in a web page or any document and you select or (text highlighted) a word or phrase... then press the keys for the shortcut eg: Ctrl+Alt+G and Firefox will open searching in google for the text you have highlighted o selected.

On the other hand I think the user55822 tried to say was the Artha
application works like this command.. the difference is by default if you have a text selected with Ctrl+Alt+W Artha will serch for that text but "offline" (As far as I know.)
But you can use both, if you need to search in Artha select the text and press the
shorcut keys Ctrl+Alt+W, but if you want to look in google "online" you can use the script with the shorcut Ctrl+Alt+G.

All the credit for the command is for user55822

Hope will be useful.

Edit: The above instructions on setting the shortcut are for Ubuntu (proper). To set the shortcut for that script (or for any script like that) in Xubuntu, see the answers to this question. To set the shortcut in Lubuntu (which does not have a GUI for that purpose):

Paste in Terminal:

sudo gedit ~/.config/openbox/lubuntu-rc.xml 

There are a lot of groups of lines that set the keybinds and look like so:

<keybind key="C-A-t">
      <action name="Execute">
        <command>x-terminal-emulator</command>
      </action>
    </keybind>

To add a keybind for the google search script, insert this at the end of one of those groups:

<keybind key="C-A-g">
      <action name="Execute">
        <command>sh ~/search-google.sh</command>
      </action>
    </keybind>   

To have a short and clear answer based on the main one:


sudo apt-get install xclip

Add the following commands (worked directly for me, no script needed), for Google search:

sh -c 'firefox "https://www.google.com/search?q=$(xclip -o)"'

For Google translate (example for French to English):

sh -c 'firefox "http://translate.google.com/#fr/en/$(xclip -o)"'

replacing the language and browser if needed.