howto,

Creating XDG custom url scheme handler

Izhar Firdaus Izhar Firdaus Follow Support Feb 18, 2021 · 1 min read
Creating XDG custom url scheme handler
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

If you develop system tools or desktop software on Linux that also have an accompanying web application, you might want to have a way for the web application to launch the tool with some parameters specified through a web based link. For example, a link with dnf://inkscape as url, might be used to launch Gnome Software, and display the description of Inkscape, so that user may choose to install it or not.

In Linux, registering a custom URL handler can be done using XDG desktop file, of which it is configured to open x-scheme-handler MimeType.

To achieve this, you can simply create a .desktop in ~/.local/share/applications/, or /usr/local/share/applications, and configure it with MimeType=x-scheme-handler/<your-custom-proto>. If nothing went wrong with the setup, you should be able to open links with the custom url protocol afterwards.

For example, if you have a script dnfurl which takes dnf://<package-name> as its first parameter and launch Gnome Software with the package name, you can create a .desktop file with this content:

[Desktop Entry]
Version=1.0
Type=Application
Name=dnfurl
Exec=dnfurl %U
Terminal=false
NoDisplay=true
MimeType=x-scheme-handler/dnf

After installing the .desktop file, do run update-desktop-database to update the related indexes/cache. If you installed the .desktop file in ~/.local/share/applications/, you will have to run update-desktop-database ~/.local/share/applications.

If you interested with the example dnfurl program above, you can check it out at this git repository: github.com/kagesenshi/dnfurl. Or if you are in Fedora, you can install it from copr by running:

dnf copr enable izhar/dnfurl
dnf install dnfurl

Have fun~.

Written by Izhar Firdaus Follow Support
I'm a system architect, data engineer and developer advocate with passion in Free / Open Source software, entrepreneurship, community building, education and martial art. I take enjoyment in bridging and bringing together different FOSS technologies to help businesses and organizations utilize IT infrastructure to aid and optimize their business and organizational process.

How to get ILI9486 Raspberry Pi 3.5" LCD to work with Fedora ARM

Fedora ARM provides a full fledged Linux distro with rich ecosystem of server packages available for the ARM ecosystem.

In howto, Feb 17, 2021

« Previous Post

The best practice method to install VirtualBox on Fedora 32/33 (and later)

In any linux distribution, there will be multiple methods to achieve a certain goal.You might have encountered many guides out there ...

In howto, Feb 22, 2021

Next Post »