MacOS – how to get Terminal’s Search with Google to open in the default browser

macosterminal

Scenario: working away in Terminal, get an error message. Want to google it so I select text and use right-click and "Search with Google". Opens Safari every time. Google Chrome is my default browser. I've restarted the machine twice since I confirmed that.

Best Answer

Search with Google is a service provided by Safari and has nothing to do with Terminal.

Google Chrome should provide its own service for this feature. It doesn't.


Or you can write your own, e.g. using Automator and AppleScript:

Open Automator and select to create a new Service. At the top, select text and any application. Then, add a Run Shell Script action from the library to the workflow by drag&drop or double-clicking. Change its input to as arguments, and paste the following script in its main text area:

#!/bin/bash
function urlencode {
    echo -n "$@" | perl -MURI::Escape -ne 'print uri_escape($_)'
}
open "http://google.com/search?q=$( urlencode "$@" )"

Automator screenshot

This will open the URL http://google.com/search?q= followed by your URL-escaped text selection in your default browser.

Save as Search with Google in Default Browser and try again.