Mac OS X (Lion) Chrome: shortcut for "Search With Google"
Solution 1
The Search With Google service is provided by Safari, and it is not meant to work with other browsers.
You can create another service yourself though:
- Open Automator and choose the Service template
- Add a Run Shell Script action for a script like
open "http://www.google.com/search?q=$(ruby -rcgi -e 'print CGI.escape $<.read.chomp')"
- Save the service and assign it a shortcut from System Preferences
Solution 2
Nowadays you can also use "Run Javascript" in automator services, and stack it with "Internet" → "Open webpages". Something like this:
JavaScript to run:
function run(input, parameters) {
return "https://www.google.com/search?q=" + encodeURI(input)
}
Screenshot of Automator "service":
Solution 3
Just wanted to add that if you use accepted answer and save the service as "Search with Google", it will be executed instead of the service of the same name that launches Safari.
Related videos on Youtube
Blaz
Updated on September 18, 2022Comments
-
Blaz over 1 year
Under Keyboard Shortcuts : Application Shortcuts I've already tried with either "Search With Google" or "Google Search..." as the Menu Item (both of these for Application set as Google Chrome, of course).
Also, even with Chrome as the default browser, the Search With Google (under Services : Searching; which works) always uses Safari.
In short, how do you set up a keyboard shortcut to avoid right-clicking the selected word and choosing Search Google for 'the selected word' from the right-click menu?
Thank you.
-
Blaz over 12 yearsLri, this is great; it works! Now, would you care to explain how approximately it works? It invokes
bash
, then ... what doesruby -e 'require "cgi"; print CGI.escape($<.read.chomp)'
do? I presume this returns back to Chrome? -
slhck over 12 years@courteous The
ruby
command reads the string you searched for and URL-escapes it. The result of this is evaluated by$()
and just appended to the Google.com line by bash. -
andilabs over 10 years@Lri THANKS FOR THAT! If somebody would like to have easy google translator access under right mouse button on OS X gist.github.com/andilab/7219174
-
Joel Mellon over 9 yearsYou can also remove the stock one by finding if accord to the instructions at osxdaily.com/2013/05/14/…
-
d-b about 7 years@slhck - how do I add quotes around the search string (e.g. search for "hello world" rather than hello world)? I have tried to add " in several locations in this command but I only end up with one " in the search string, either in the beginning or at the end.
-
slhck about 7 years@d-b Can't confirm, it works for me when I add double quotes.
-
d-b about 7 years@slhck Where do you add the double quotes? Can you post your oneliner?
-
slhck about 7 years@d-b I just run
open "http://www.google.com/search?q=$(ruby -rcgi -e 'print CGI.escape $<.read.chomp')"
, then enter"Hello World"
, then pressCtrl-D
.https://www.google.com/search?q="Hello+World"
opens. -
d-b about 7 years@slhck Aah, but that requires that the search phrase contains double quotes in itself. I want to select a couple of words that is not quoted (company names in fact) and search for them at Google within quotes. Sorry for the misunderstanding.
-
Jason Harrison about 7 yearsMore screenshots of how to create and connect the service stackoverflow.com/questions/17935301/…
-
noamtm over 6 yearsThese days (2018) this is by far the best answer.
-
Jerry101 almost 6 yearsThat added a second "Search with Google" command to the context menu until I unchecked the one in Preferences - Keyboard - Services - Searching.