DEV Community

Cover image for Creating XDG custom url scheme handler
Izhar Firdaus
Izhar Firdaus

Posted on • Originally published at blog.kagesenshi.org on

Creating XDG custom url scheme handler

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>.

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 .desktopfile with this content:

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

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 nothing went wrong with the setup, you should be able to open links with the custom url protocol afterwards.

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
Enter fullscreen mode Exit fullscreen mode

Have fun~.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay