Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm looking for a script (or Launchbar action, or an application) which will take the highlighted text from the front window of any application and send it to my default browser to search in Google. I'd like to be able to bind it to a system-wide keyboard shortcut. I'd like to be able to highlight some text, press a key and have the Google results opened in my browser.

share|improve this question

1 Answer 1

up vote 3 down vote accepted

It already exists in Program Name Menu » Services » Search With Google (only visible with text selection). Assign a keyboard shortcut in System Preferences » Keyboard » Keyboard Shortcuts » Services. This one always uses Safari though.

It's possible that your browser provides a similar Service already, if it has proper integration into OS X and isn't a cross-platform piece of garbage. Just check the list whether you see an appropriate entry.


If you want to build it yourself, or want to use your non-Safari default browser:

Open /Applications/Automator.app, select to create a Service.

In the bar at the upper right, select Service receives text as input in any application.

From the library at the left, double-click Run Shell Script in Utilities.

In the new element, select Pass input: as arguments and enter the following text into the text box:

open "http://www.google.com/search?q=${@}"

Save as e.g. "Search Selection in Google".

share|improve this answer
    
The Automator action worked perfectly since my browser of choice (Firefox) is a cross platform piece of garbage. Thanks so much, you've saved me many hours of cmd-c cmd-tab cmd-l tab cmd-v. –  nevan king Sep 2 '11 at 15:48
    
For whatever reason, this service works in Firefox too. When I use my keyboard shortcut, the "Firefox" menu flashes and it searches, even though Firefox's service menu is empty. –  nevan king Sep 2 '11 at 15:57
    
@nevan I changed the default browser and the page still opened in Safari, so I didn't expect the default shortcut to work like this. –  Daniel Beck Sep 2 '11 at 16:00
    
With mine, the built-in "Search with Google" service always opens Safari. The Automator service I made always opens with Firefox, my default browser. Both service work from Safari and Firefox. I realized that Firefox does have Services, but only when you select some text. –  nevan king Sep 2 '11 at 16:09
    
@nevan That's what I meant. Services work in (almost) any application (except some cross-platform programs), but their capabilities might redirect to other programs, e.g. Firefox or a text editor initiating a search in Safari. Using open (a command-line tool), as my service does, uses the system's default browser. You could also enforce use of Firefox: open -a Firefox "http://..." even though Safari might be your default browser. I just suggested that some browsers might provide a "Search With Google using Opera/Firefox..." service for better OS integration. –  Daniel Beck Sep 2 '11 at 16:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.