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 need this shortcut when some website display link in plain text, or I wanna google some words in the page.

Right-clicking the menu can do this, but I'd like only use the keyboard which is much more effective.

Now I use Cmd-C, Cmd-T, Cmd-V, Enter to do this.

share|improve this question
    
It would be cool if an extension made all words links when holding down ctrl –  Aram Kocharyan Jan 30 '12 at 10:33
    
What's wrong with pressing three keys or two clicks? –  Tom Wijsman Jan 30 '12 at 11:33
add comment

4 Answers

up vote 3 down vote accepted

There's a built-in service that opens a selected text URL in a default application. It requires the URL to have a scheme though and doesn't fall back to a Google search or anything.


You could also create a custom service that opens a URL or a Google search page:

input="$(cat)"
input="${input%\n}" # remove a possible trailing newline
if [[ "$input" =~ '://' ]]; then
    open "$input"
else
    open "http://www.google.com/search?q=$(echo -En "$input" |
    ruby -e 'require "cgi"; print CGI.escape($<.read.chomp)')"
fi
share|improve this answer
    
Of course, it only works when actual URLs are highlighted. Do you have an idea how to make Google actually search for custom text, without resorting to UI scripting? –  slhck Jan 30 '12 at 16:36
    
@slhck I edited the answer. And if anyone is looking for a service or script that would support local paths or multiple URLs, see selection open.scpt in lri.me/aspack. –  Lri Jan 30 '12 at 16:56
add comment

For the benefit of anyone looking at this question in 2014 or beyond, Google Chrome has implemented this feature.

Chrome go to URL

share|improve this answer
add comment

Open Automator.app and create a new "Service". Choose "Service receives selected text", and choose "Google Chrome" as the application.

Then, drag "Run AppleScript" from the left pane to the right and paste:

on run {input, parameters}

    tell application "Google Chrome"
        set myTab to make new tab at end of tabs of window 1
        set URL of myTab to input
    end tell

    return input
end run

enter image description here

Then, save this Service, and give it a name like "Open selected text in Google Chrome".

Finally, go to System Preferences » Keyboard » Keyboard Shortcuts and look under "Services". Here, create a shortcut for your new service, e.g. Cmd-Shift-O.

enter image description here

This does currently not work for searching since Chrome doesn't treat text as an URL for opening. See @Lri's solution for this.

share|improve this answer
add comment

It can be done much simpler:

  1. Select the text.

  2. Drag the text to your address bar.

  3. Press Enter.

share|improve this answer
    
That doesn't work in Chrome on OS X (guessing because the OP uses Cmd keyboard shortcuts) –  slhck Jan 30 '12 at 12:54
    
@slhck: So you are just guessing entirely? It's remarkable that a lot of people are unaware of drag moving and/or copying, and I don't think those shortcuts are used as an alternative... –  Tom Wijsman Jan 30 '12 at 14:16
    
Well, I'm pretty certain, because why would one use Cmd keyboard shortcuts on Windows? You wouldn't even have to drag, you can just right-click. But as I said, dragging doesn't work for just selected text. –  slhck Jan 30 '12 at 14:20
add comment

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.