I want to use
xdg-open to open
irc:// links, how can I make the required parameter?
I want to use
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:
$ file -i Broken_Blossoms.webm Broken_Blossoms.webm: video/webm; charset=binary $
For the above file, MIME type is
For URI handlers, the type is
<scheme>is the part of URI before colon, e.g. "http", "mailto" "irc" or "magnet". Following are examples of valid MIME types:
x-scheme-handler/http x-scheme-handler/irc x-scheme-handler/magnet x-scheme-handler/mailto
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:
$ grep "Transmission" -l -r /usr/share/applications /usr/share/applications/transmission-gtk.desktop $
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
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:
$ xdg-mime default transmission-gtk.desktop x-scheme-handler/magnet $
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:
$ xdg-mime query default x-scheme-handler/magnet transmission-gtk.desktop $
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:
grep ^video/ | cut -d\t -f1 | xargs xdg-mime default vlc.desktop
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 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
xchat-2.8.8/src/common/dbus/apps_xchat_url_handler.schemas as an example.
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 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:
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:
- Install the app manually (download and unpack a tar.gz) in
- Create a desktop file in
[Desktop Entry] Version=1.0 Type=Application Name=Postman Icon=/home/andrzej.rehmann/software/postman/app/resources/app/assets/icon.png Exec="/home/andrzej.rehmann/software/postman/Postman" %u Comment=Develop with pleasure! Categories=Development; Terminal=false StartupWMClass=Postman
- Associate the
postmanxdg 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