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.


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

[Desktop Entry]
Name=DDG Scheme Handler
Exec=open-ddg.sh %u

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:


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

if [[ "$1" == "ddg:"* ]]; then
    #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"
    xdg-open "$1" # Just open with the default handler

If you have mimeo installed, and you already know the name of the Desktop file for the app you want to create the association for, it is as easy as doing:

mimeo --add 'x-scheme-handler/ddg' <path or name of desktop file>

For example, if duckduckgo, desktop file is at /usr/share/applications/Duckduckgo.desktop, then you just need:

mimeo --add 'x-scheme-handler/ddg' Duckduckgo


mimeo --add 'x-scheme-handler/ddg' /usr/share/applications/Duckduckgo.desktop

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.