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.

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. –  courteous 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. :) –  courteous Dec 26 '11 at 16:58

2 Answers 2

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.) –  courteous Dec 28 '11 at 11:10

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). –  courteous 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.