I'll describe this with magnet: URI type and Transmission (i.e. case of
bittorent), but the same method can be applied to any scheme or file type.
Also I checked this with Debian Jessie, and I don't actually have Ubuntu
machine, but I believe it should work the same (at least for xdg-open,
note that file managers may choose to use different logic).
Find out the MIME type string. For file MIME types, you can
find it out with file command:
For URI handlers, the type is x-scheme-handler/<scheme>, where
<scheme> is the part of URI before colon, e.g. "http", "mailto"
"irc" or "magnet". Following are examples of valid MIME types:
Often it's not the same as the "official" name but rather lowercase
version of it, or a completely different name. Installed .desktop
files live under /usr/share/applications. Since they are normal text
files and contain the "official" name, following command can help you:
The command effectively means "list files under this directory
that contain word 'Transmission'". Some applications may
be installed only for user, in that case the path would be
~/.local/share/applications.
In case you have "strange" application that may not have the file
at all, you can always create one (and perhaps send it to the app
developers). Easy way would be to copy an existing one, rewrite
fields you understand and remove those you don't. Refer to the
specification for details.
Note that no matter where the file actually is
(/usr/share/applications, ~/.local/share/applications...), you always use
only the name, not the full path.
Normally the command will not output anything--that's OK. If you
want to verify what you just did or see what is currently assigned
to any MIME type without opening it:
Note 1: If you want to check out other MIME types, you can look
at /etc/mime.types. It does not contain all types in the world; for
example the URI handlers, but it could be used for "aggressive" form
of handling the associations. For example:
Note 2: The .desktop files often contain list of MIME types that
they claim to be able to handle using MimeType field. xdg-mime
man page says that the .desktop file must claim the MIME type before
the above mentioned command will work, but for me it seems to work even
if the field is missing. (I mean, the association will be applied and
the application will launch--if it really can handle the type is a
different question). I'm not sure what is drawback (maybe in future
the xdg-mime will be more restrictive).
xdg-open basically just looks to see which desktop environment you have and then runs gnome-open, gvfs-open, xfce-open, etc. See below for desktop environment specific instructions...
Gnome
Gnome uses the gnome-open program which uses gconf to store everything. For example on my machine with Ubuntu 10.10 running gnome-open irc://blah opens up xchat because xchat includes a gconf setting patch to add an irc:// handler.
This shows how gnome does this, with a gconf settings in /desktop/gnome/url-handlers/. See xchat-2.8.8/src/common/dbus/apps_xchat_url_handler.schemas as an example.
KDE
For KDE you should look at the .protocol files in /usr/share/kde4/services/, create a new one for your new protocol and put it in ~/.kde/share/kde4/services/, if it's super useful then consider adding it to the package as a fix for other users.
KDE is using kde-open or kfmclient depending on what's available and what version of KDE you have.
XFCE
XFCE uses a program called exo-open, this program doesn't have any way to configure it or add uri handlers. Looking through the source code shows that is uses desktop files to specify only three types of programs. TerminalEmulator, WebBrowser and EmailClient.
With XFCE4 (and probably also others) it is possible to configure xdg-open to define a custom protocol handler. In some you have to create/edit the following files:
I wanted to associate postman links with my manually installed Postman app (not the chrome extension) so that I could open postman docs from the browser like this:
I'll describe this with
magnet:
URI type and Transmission (i.e. case of bittorent), but the same method can be applied to any scheme or file type.Also I checked this with Debian Jessie, and I don't actually have Ubuntu machine, but I believe it should work the same (at least for xdg-open, note that file managers may choose to use different logic).
Find out the MIME type string. For file MIME types, you can find it out with file command:
For the above file, MIME type is
video/webm
.For URI handlers, the type is
x-scheme-handler/<scheme>
, where<scheme>
is the part of URI before colon, e.g. "http", "mailto" "irc" or "magnet". Following are examples of valid MIME types:Find out the name of application .desktop file.
Often it's not the same as the "official" name but rather lowercase version of it, or a completely different name. Installed .desktop files live under /usr/share/applications. Since they are normal text files and contain the "official" name, following command can help you:
The command effectively means "list files under this directory that contain word 'Transmission'". Some applications may be installed only for user, in that case the path would be
~/.local/share/applications
.In case you have "strange" application that may not have the file at all, you can always create one (and perhaps send it to the app developers). Easy way would be to copy an existing one, rewrite fields you understand and remove those you don't. Refer to the specification for details.
Make the assignment using xdg-mime command:
Note that no matter where the file actually is (/usr/share/applications, ~/.local/share/applications...), you always use only the name, not the full path.
Normally the command will not output anything--that's OK. If you want to verify what you just did or see what is currently assigned to any MIME type without opening it:
Note 1: If you want to check out other MIME types, you can look at /etc/mime.types. It does not contain all types in the world; for example the URI handlers, but it could be used for "aggressive" form of handling the associations. For example:
would associate all known video formats to VLC.
Note 2: The .desktop files often contain list of MIME types that they claim to be able to handle using
MimeType
field. xdg-mime man page says that the .desktop file must claim the MIME type before the above mentioned command will work, but for me it seems to work even if the field is missing. (I mean, the association will be applied and the application will launch--if it really can handle the type is a different question). I'm not sure what is drawback (maybe in future the xdg-mime will be more restrictive).xdg-open basically just looks to see which desktop environment you have and then runs gnome-open, gvfs-open, xfce-open, etc. See below for desktop environment specific instructions...
Gnome
Gnome uses the gnome-open program which uses gconf to store everything. For example on my machine with Ubuntu 10.10 running gnome-open irc://blah opens up xchat because xchat includes a gconf setting patch to add an irc:// handler.
This shows how gnome does this, with a gconf settings in
/desktop/gnome/url-handlers/
. Seexchat-2.8.8/src/common/dbus/apps_xchat_url_handler.schemas
as an example.KDE
For KDE you should look at the .protocol files in /usr/share/kde4/services/, create a new one for your new protocol and put it in ~/.kde/share/kde4/services/, if it's super useful then consider adding it to the package as a fix for other users.
KDE is using kde-open or kfmclient depending on what's available and what version of KDE you have.
XFCE
XFCE uses a program called exo-open, this program doesn't have any way to configure it or add uri handlers. Looking through the source code shows that is uses desktop files to specify only three types of programs. TerminalEmulator, WebBrowser and EmailClient.
With XFCE4 (and probably also others) it is possible to configure xdg-open to define a custom protocol handler. In some you have to create/edit the following files:
~/.local/share/applications/protocolhandler.desktop ~/.local/share/applications/mimeapps.list
An example adding a handler for the ed2k protocol is provided at stackexchange.com2.
I wanted to associate
postman
links with my manually installed Postman app (not the chrome extension) so that I could open postman docs from the browser like this:The link I wanted to associate looks like this:
To do the association I did the following steps:
/home/andrzej.rehmann/software/postman/
/usr/share/applications/Postman.desktop
postman
xdg link with the application by running:xdg-mime default Postman.desktop x-scheme-handler/postman
I've ansibled this configuration if anyone is interested: https://github.com/hoto/ansible-home-fedora/blob/fedora/roles/postman/tasks/postman_installer.yml