Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

As an extension of previous question, how would one add a keyboard shortcut for right-clicking a URL and selecting "Go to http:// ..." in Chrome?

Could it be done using the same shortcut as in the previous question ( + + L)? Say, by adding some reg-exp for "http://"?

Thank you for any help.

share|improve this question
    
Please clarify, do you want a new entry in the context menu of a URL that opens the selected URL in Chrome? – Daniel Beck Dec 26 '11 at 12:14
    
@DanielBeck I'm looking for a keyboard shortcut, so as to avoid right-clicking some-selected-URL and choosing Go to http://selected.site.com. Analogous to what Lri managed in my previous question. – Blaz Dec 26 '11 at 16:39
    
Thanks for clarifying. You only want that in Chrome, or in any application? – Daniel Beck Dec 26 '11 at 16:53
    
@DanielBeck Only in Chrome (for avoiding any potential conflicts, I guess). I'm fairly new to OSx, so any help is greatly appreciated. :) – Blaz Dec 26 '11 at 16:58
up vote 1 down vote accepted

Unlike the Search With Google service, Open URL actually works with other browsers than Safari.


A 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
    
Lri, thank you once again. The extension of your Bash script from the previous question did the trick (that is, it uses a single shortcut). (I'd also vote-up, if only I had 15 reputation points.) – Blaz Dec 28 '11 at 11:10
    
My system already had an "Open URL" service, and I've confirmed that I can use it to open a url that's selected from a text window. There's no shortcut, so I set the shortcut to be ⌘⇧U. But when I try the shortcut, I only hear the "thump" sound. Is there something else I need to do to make the shortcut become active? – Edward Falk Jun 6 at 22:26

Chrome's AppleScript API makes this task non-obvious, so I'll stick to the basics, once again using Automator:

enter image description here

for f in "$@"
do
    if [[ "${f:0:7}" != "http://" && "${f:0:8}" != "https://" ]] ; then
        f="http://$f"
    fi
    open -a "Google Chrome" "$f"
done

There's some rudimentary logic that makes e.g. "example.org" into a proper URL with http:// scheme.


Since you also want the scope to be different (all applications vs. just Chrome) it's not possible to limit it to a single keyboard shortcut. Just assign a different one for this.

share|improve this answer
    
Thanks for the help, but I'll have to go with Lri's more complete answer (which uses a single shortcut). – Blaz Dec 28 '11 at 11:08

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.