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.
Best Answer
To register a new URL scheme handler with XDG, first create a Desktop Entry which specifies the
x-scheme-handler/...
MIME type: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 Entryddg-opener.desktop
):A reference implementation of the
ddg-open.sh
handler: