3

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.

4
  • 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, 2011 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, 2011 at 16:39
  • Thanks for clarifying. You only want that in Chrome, or in any application?
    – Daniel Beck
    Dec 26, 2011 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, 2011 at 16:58

2 Answers 2

1

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
2
  • 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, 2011 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? Jun 6, 2016 at 22:26
1

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .