Open address in external application from inside Chrome Browser

12,759

One cannot any more directly call on Chrome an external application except via a dedicated extension, but I could not find one that does not use NPAPI.

There is still one method that should work, that needs to be set up in the operating system: Custom Protocols, called also Custom URI Schemes.

A URI scheme is the part that one find at the beginning of the URL. Some common ones are : http(s)://, ftp://, feed://, mailto:, news:. The list of all known ones can be found in the IANA list of Uniform Resource Identifier (URI) Schemes.

All that these protocols do is launch an application that handles the parameter. Once the application has successfully launched, it can use command-line parameters to retrieve the URI that launched it. The usual method is to call a known script that processes its argument and launches the required program.

Including here a tutorial for Windows, Linux and Mac is much too heavy, but here are some useful references :


To answer the request by the poster, below is a Linux KDE script that sets /path/prog as handler for the protocol xyz://. It creates for KDE the file $KDEDIR/share/services/xyz.protocol and populates it. The Gnome settings are also set (if possible) since some applications still use them even if running on KDE. The script is adapted from github.

#!/usr/bin/env bash
#
#    This script attempts to register a protocol handler for
#    links that look like sgaction://blah.  
#
#    It should be sufficient for gnome apps like pidgin and kde apps
#    like konqueror.  Firefox seems to pay attention to the gnome
#    settings at least to the degree that it recognizes links of the
#    form $protocol://blah as hot-links, but it may still ask you to
#    select the application the first time you click on one.

protocol=xyz
handler="/path/prog"

echo "Installing $protocol protocol handler for Gnome."

gconfTool="$(which gconftool-2)"
if [[ "$gconfTool" ]]; then
    gconftool-2 --set --type=string /desktop/gnome/url-handlers/$protocol/command "$handler \"%s\""
    gconftool-2 --set --type=bool /desktop/gnome/url-handlers/$protocol/enabled true
    gconftool-2 --set --type=bool /desktop/gnome/url-handlers/$protocol/need-terminal false
else
    echo "WARNING: gconftool-2 not found: skipping gnome url-handler registration."
fi


echo "Installing $protocol protocol handler for KDE."

kdeProtoDir=~/.kde/share/services

if [[ "$KDEDIR" ]]; then
    kdeProtoDir="$KDEDIR/share/services"
fi

if [[ ! -e "$kdeProtoDir" ]]; then
    mkdir -p "$kdeProtoDir"
fi

if [[ -e "$kdeProtoDir" ]]; then
    kdeProtoFile="$kdeProtoDir/$protocol.protocol"
    rm -f $kdeProtoFile
    cat > $kdeProtoFile << EOF
[Protocol]
exec=$handler "%u"
protocol=$protocol
input=none
output=none
helper=true
listing=false
reading=false
writing=false
makedir=false
deleting=false
EOF
else
    echo "WARNING: can't find or create KDE protocol directory: $kdeProtoDir:  skipping KDE url-handler registration."
fi


echo "Done."
Share:
12,759

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin almost 2 years

    enter image description here

    After Chrome browser has abandoned NPAPI-based extensions (which included addons for this purpose, similar to Openwith and Flashgot from Firefox) is there a way of sending a link from the browser to an external application (like other browser, a video player, custom downloader, etc.)?

    This NPAPI addon is called just like that: "Open with external application".

    Is there an alternative to that given the change that took place?

  • Admin
    Admin over 7 years
    I don't think normally browsers have that feature but with an addon it should be possible. There were such addons that are not working anymore.
  • Admin
    Admin over 7 years
  • Admin
    Admin over 7 years
    Until new extensions are published the solutions indicated are OS-specific and require a level of competence that is beyond my reach. I use mostly Linux. I guess I will have to wait until non-npapi extensions are published (I wander why it takes so long, the demand must be huge),
  • harrymc
    harrymc over 7 years
    I can list the required steps for Linux. Which Linux version and are you using KDE or Gnome (and which Gnome version) ?
  • Admin
    Admin over 7 years
    That would be great! I am using multiple Linux-es but my main one is KDE (Mint 18 with Plasma 5).
  • harrymc
    harrymc over 7 years
    I have added a bash script that may do the job. I cannot test, so I'm doing it by theory.
  • Admin
    Admin over 7 years
    I am granting the bounty for now. But I will not set a definitive answer. I was looking for a ready-made extension or possibly a userscript in Tempermonkey that will allow what I ask. I have no idea how to use your script, I would need much more details. (Saved were? launched how? how is it accessible in Chrome?)
  • harrymc
    harrymc over 7 years
    This one-time script is to be launched with sudo, after setting the parameters of protocol and handler. It will enable you to launch some program/script of yours with the link as parameter. You should study the links I gave in order to find how to use custom URIs. A userscript is certainly possible if you have a definite idea what is to be changed. Go slowly and google for more details as you advance.