Create a custom URL Protocol Handler












0















I would like to register a URL scheme (or protocol) handler for my own custom URL protocol, so that clicking on a link with this custom protocol will execute a command on that URL. Which steps do I need to take to add this handler?



Example: I want to open URLs like ddg://query%20terms in a new DuckDuckGo browser search. If this protocol already exists, I assume that the steps to override a handler don't differ much from the steps to create a new one. Yes, technically, this is just a URL scheme, not a protocol.









share



























    0















    I would like to register a URL scheme (or protocol) handler for my own custom URL protocol, so that clicking on a link with this custom protocol will execute a command on that URL. Which steps do I need to take to add this handler?



    Example: I want to open URLs like ddg://query%20terms in a new DuckDuckGo browser search. If this protocol already exists, I assume that the steps to override a handler don't differ much from the steps to create a new one. Yes, technically, this is just a URL scheme, not a protocol.









    share

























      0












      0








      0








      I would like to register a URL scheme (or protocol) handler for my own custom URL protocol, so that clicking on a link with this custom protocol will execute a command on that URL. Which steps do I need to take to add this handler?



      Example: I want to open URLs like ddg://query%20terms in a new DuckDuckGo browser search. If this protocol already exists, I assume that the steps to override a handler don't differ much from the steps to create a new one. Yes, technically, this is just a URL scheme, not a protocol.









      share














      I would like to register a URL scheme (or protocol) handler for my own custom URL protocol, so that clicking on a link with this custom protocol will execute a command on that URL. Which steps do I need to take to add this handler?



      Example: I want to open URLs like ddg://query%20terms in a new DuckDuckGo browser search. If this protocol already exists, I assume that the steps to override a handler don't differ much from the steps to create a new one. Yes, technically, this is just a URL scheme, not a protocol.







      url xdg xdg-open





      share












      share










      share



      share










      asked 3 mins ago









      palswimpalswim

      1,62611732




      1,62611732






















          1 Answer
          1






          active

          oldest

          votes


















          0














          To register a new URL scheme handler with XDG, first create a Desktop Entry which specifies the x-scheme-handler/... MIME type:



          [Desktop Entry]
          Type=Application
          Name=DDG Scheme Handler
          Exec=open-ddg.sh %u
          StartupNotify=false
          MimeType=x-scheme-handler/ddg;


          Note that %u passes the URL (e.g. ddg://query%20terms) as a single parameter, according to the Desktop Entry Specification.



          Once you have created this Desktop Entry and installed it (i.e. put it in the local or system applications directory for XDG, like ~/.local/share/applications/ or /usr/share/applications/), then you must register the application with the MIME type (assuming you had named your Desktop Entry ddg-opener.desktop):



          xdg-mime default ddg-opener.desktop x-scheme-handler/ddg


          A reference implementation of the ddg-open.sh handler:



          #!/bin/bash

          # bash and not just sh because we are using some bash-specific syntax

          if [[ "$1" == "ddg:"* ]]; then
          ref=${1#ddg://}
          #ref=$(python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])" "$ref") # If you want decoding
          xdg-open "https://duckduckgo.com/?q=$ref"
          else
          xdg-open "$1" # Just open with the default handler
          fi




          share
























          • I was able to piece together this answer from this Question and its Answer, but I wanted to make a more generic question and guide.

            – palswim
            1 min ago











          • For the handler, you can add encoding and decoding of the URL and parameters through Python.

            – palswim
            just now











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "106"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f497146%2fcreate-a-custom-url-protocol-handler%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          To register a new URL scheme handler with XDG, first create a Desktop Entry which specifies the x-scheme-handler/... MIME type:



          [Desktop Entry]
          Type=Application
          Name=DDG Scheme Handler
          Exec=open-ddg.sh %u
          StartupNotify=false
          MimeType=x-scheme-handler/ddg;


          Note that %u passes the URL (e.g. ddg://query%20terms) as a single parameter, according to the Desktop Entry Specification.



          Once you have created this Desktop Entry and installed it (i.e. put it in the local or system applications directory for XDG, like ~/.local/share/applications/ or /usr/share/applications/), then you must register the application with the MIME type (assuming you had named your Desktop Entry ddg-opener.desktop):



          xdg-mime default ddg-opener.desktop x-scheme-handler/ddg


          A reference implementation of the ddg-open.sh handler:



          #!/bin/bash

          # bash and not just sh because we are using some bash-specific syntax

          if [[ "$1" == "ddg:"* ]]; then
          ref=${1#ddg://}
          #ref=$(python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])" "$ref") # If you want decoding
          xdg-open "https://duckduckgo.com/?q=$ref"
          else
          xdg-open "$1" # Just open with the default handler
          fi




          share
























          • I was able to piece together this answer from this Question and its Answer, but I wanted to make a more generic question and guide.

            – palswim
            1 min ago











          • For the handler, you can add encoding and decoding of the URL and parameters through Python.

            – palswim
            just now
















          0














          To register a new URL scheme handler with XDG, first create a Desktop Entry which specifies the x-scheme-handler/... MIME type:



          [Desktop Entry]
          Type=Application
          Name=DDG Scheme Handler
          Exec=open-ddg.sh %u
          StartupNotify=false
          MimeType=x-scheme-handler/ddg;


          Note that %u passes the URL (e.g. ddg://query%20terms) as a single parameter, according to the Desktop Entry Specification.



          Once you have created this Desktop Entry and installed it (i.e. put it in the local or system applications directory for XDG, like ~/.local/share/applications/ or /usr/share/applications/), then you must register the application with the MIME type (assuming you had named your Desktop Entry ddg-opener.desktop):



          xdg-mime default ddg-opener.desktop x-scheme-handler/ddg


          A reference implementation of the ddg-open.sh handler:



          #!/bin/bash

          # bash and not just sh because we are using some bash-specific syntax

          if [[ "$1" == "ddg:"* ]]; then
          ref=${1#ddg://}
          #ref=$(python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])" "$ref") # If you want decoding
          xdg-open "https://duckduckgo.com/?q=$ref"
          else
          xdg-open "$1" # Just open with the default handler
          fi




          share
























          • I was able to piece together this answer from this Question and its Answer, but I wanted to make a more generic question and guide.

            – palswim
            1 min ago











          • For the handler, you can add encoding and decoding of the URL and parameters through Python.

            – palswim
            just now














          0












          0








          0







          To register a new URL scheme handler with XDG, first create a Desktop Entry which specifies the x-scheme-handler/... MIME type:



          [Desktop Entry]
          Type=Application
          Name=DDG Scheme Handler
          Exec=open-ddg.sh %u
          StartupNotify=false
          MimeType=x-scheme-handler/ddg;


          Note that %u passes the URL (e.g. ddg://query%20terms) as a single parameter, according to the Desktop Entry Specification.



          Once you have created this Desktop Entry and installed it (i.e. put it in the local or system applications directory for XDG, like ~/.local/share/applications/ or /usr/share/applications/), then you must register the application with the MIME type (assuming you had named your Desktop Entry ddg-opener.desktop):



          xdg-mime default ddg-opener.desktop x-scheme-handler/ddg


          A reference implementation of the ddg-open.sh handler:



          #!/bin/bash

          # bash and not just sh because we are using some bash-specific syntax

          if [[ "$1" == "ddg:"* ]]; then
          ref=${1#ddg://}
          #ref=$(python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])" "$ref") # If you want decoding
          xdg-open "https://duckduckgo.com/?q=$ref"
          else
          xdg-open "$1" # Just open with the default handler
          fi




          share













          To register a new URL scheme handler with XDG, first create a Desktop Entry which specifies the x-scheme-handler/... MIME type:



          [Desktop Entry]
          Type=Application
          Name=DDG Scheme Handler
          Exec=open-ddg.sh %u
          StartupNotify=false
          MimeType=x-scheme-handler/ddg;


          Note that %u passes the URL (e.g. ddg://query%20terms) as a single parameter, according to the Desktop Entry Specification.



          Once you have created this Desktop Entry and installed it (i.e. put it in the local or system applications directory for XDG, like ~/.local/share/applications/ or /usr/share/applications/), then you must register the application with the MIME type (assuming you had named your Desktop Entry ddg-opener.desktop):



          xdg-mime default ddg-opener.desktop x-scheme-handler/ddg


          A reference implementation of the ddg-open.sh handler:



          #!/bin/bash

          # bash and not just sh because we are using some bash-specific syntax

          if [[ "$1" == "ddg:"* ]]; then
          ref=${1#ddg://}
          #ref=$(python -c "import sys, urllib as ul; print ul.unquote_plus(sys.argv[1])" "$ref") # If you want decoding
          xdg-open "https://duckduckgo.com/?q=$ref"
          else
          xdg-open "$1" # Just open with the default handler
          fi





          share











          share


          share










          answered 3 mins ago









          palswimpalswim

          1,62611732




          1,62611732













          • I was able to piece together this answer from this Question and its Answer, but I wanted to make a more generic question and guide.

            – palswim
            1 min ago











          • For the handler, you can add encoding and decoding of the URL and parameters through Python.

            – palswim
            just now



















          • I was able to piece together this answer from this Question and its Answer, but I wanted to make a more generic question and guide.

            – palswim
            1 min ago











          • For the handler, you can add encoding and decoding of the URL and parameters through Python.

            – palswim
            just now

















          I was able to piece together this answer from this Question and its Answer, but I wanted to make a more generic question and guide.

          – palswim
          1 min ago





          I was able to piece together this answer from this Question and its Answer, but I wanted to make a more generic question and guide.

          – palswim
          1 min ago













          For the handler, you can add encoding and decoding of the URL and parameters through Python.

          – palswim
          just now





          For the handler, you can add encoding and decoding of the URL and parameters through Python.

          – palswim
          just now


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Unix & Linux Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f497146%2fcreate-a-custom-url-protocol-handler%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Accessing regular linux commands in Huawei's Dopra Linux

          Can't connect RFCOMM socket: Host is down

          Kernel panic - not syncing: Fatal Exception in Interrupt