Create a custom URL Protocol Handler
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
add a comment |
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
add a comment |
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
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
url xdg xdg-open
asked 10 mins ago
palswimpalswim
1,62611732
1,62611732
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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
8 mins ago
For the handler, you can add encoding and decoding of the URL and parameters through Python.
– palswim
7 mins ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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
8 mins ago
For the handler, you can add encoding and decoding of the URL and parameters through Python.
– palswim
7 mins ago
add a comment |
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
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
8 mins ago
For the handler, you can add encoding and decoding of the URL and parameters through Python.
– palswim
7 mins ago
add a comment |
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
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
answered 10 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
8 mins ago
For the handler, you can add encoding and decoding of the URL and parameters through Python.
– palswim
7 mins ago
add a comment |
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
8 mins ago
For the handler, you can add encoding and decoding of the URL and parameters through Python.
– palswim
7 mins 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
8 mins 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
8 mins ago
For the handler, you can add encoding and decoding of the URL and parameters through Python.
– palswim
7 mins ago
For the handler, you can add encoding and decoding of the URL and parameters through Python.
– palswim
7 mins ago
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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