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.

Blaz
  • 783

2 Answers2

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.

Daniel Beck
  • 111,893
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
Lri
  • 42,502
  • 8
  • 126
  • 159