How do I change default associations for URI schemas?

In Windows, ms-settings:defaultapps allows you to change the default associations for URI schemas (like vscode:) in addition to file extensions.

In contrast, kcmshell6 kcm_filetypes solely appears to be capable of setting them for (custom) IANA Media Type-representations of file extensions.

Consequently, how can these be configured (outside of the web browser, considering that they can be invoked elsewhere)?

There are essentially two levels to that.

When applications get installed they usually also install a so called “desktop file”.
Global location for distribution packages is /usr/share/applications on most distributions, user local default location is $HOME/.local/share/applications

Each application can list its URI scheme capabilities in its .desktop file, for example the steam.desktop file on my system has a line like this
MimeType=x-scheme-handler/steam;x-scheme-handler/steamlink;

and the signal-desktop.desktop file has a line like this
MimeType=x-scheme-handler/sgnl;x-scheme-handler/signalcaptcha;

As long as there is only one application for a given scheme that application is obviously also the default.

Now, if multiple applications have support for a scheme, the mimeapps.list file is consulted.
Its system default location is /etc/xdg/mimeapps.list and its user local default location is $HOME/.config/mimeapps.list

It can have a section called [Default Applications} with entries like
x-scheme-handler/sgnl=signal-desktop.desktop
making signal-desktop.desktop the default for sgnl:// URIs.

On a tool level you can make use of xdg-mime to query and set such associations

“Tell me which application handles sgnl:// URIs”
xdg-mime query default x-scheme-handler/sgnl

“I want Signal to handle sgnl:// URIs”
xdg-mime default signal-desktop.desktop x-scheme-handler/sgnl

2 Likes

@krake, thanks. Lots. I presume this functionality isn’t exposed via systemsettings too?

@rokejulianlockhart I am happy this was helpful :slight_smile:

I didn’t find anything for this in System Settings myself either but I might not have all modules installed.

If not I would guess that could be added relatively easily.
Maybe add an entry in the Brainstorm section?

1 Like

Right; the Default Applications page in System Settings shows a hardcoded set of URI handlers, not all of them that are available on the system.

1 Like

One additional question for verification… will the .desktop MimeType on ~.local/share/applications supercede those from /usr/share/applications?

1 Like

That’s correct.

1 Like

This is simplified version of how I set qbittorrent as magnet handler.

$ rpm -ql qbittorrent | grep desktop
/usr/share/applications/org.qbittorrent.qBittorrent.desktop
$ 
$ xdg-mime default org.qbittorrent.qBittorrent.desktop x-scheme-handler/magnet
$ 
$ xdg-mime query default x-scheme-handler/magnet
org.qbittorrent.qBittorrent.desktop
$ 
1 Like
$ cat ~/.config/mimeapps.list | grep magnet
x-scheme-handler/magnet=org.qbittorrent.qBittorrent.desktop;
x-scheme-handler/magnet=org.qbittorrent.qBittorrent.desktop

First one in [Added Association]. Second one in [Default Application]

1 Like