Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use xdg-open to open irc:// links, how can I make the required parameter?

share|improve this question
related bug: – cweiske Jan 16 '12 at 11:54
you can get help from this question "How can I open irc:// links in Pidgin from Chromium?" – Khurshid Alam Nov 13 '12 at 9:33
up vote 15 down vote accepted

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.

gconf-editor showing irc with xchat configuration

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.


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:

~/.local/share/applications/protocolhandler.desktop ~/.local/share/applications/mimeapps.list

An example adding a handler for the ed2k protocol is provided at stackexchange.com2.

share|improve this answer
Can you mention how to do that for all official DEs? – Oxwivi Sep 22 '11 at 20:17
Not exactly related to the question, but can you quote in full the directory at the bottom of the screen shot? Thank you. – Oxwivi Sep 23 '11 at 13:03
xdg-open basically just looks to see which desktop environment you have and then runs gnome-open, gvfs-open, xfce-open, etc. --- I don't think so. First, the manpage does not say that, and second, xdg-open works perfectly without desktop environment. For example I use it with i3 window manager. – Alois Mahdal Nov 30 '14 at 20:21

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

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

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

    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.

  3. 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 or a sub-directory of one of them, 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

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

share|improve this answer gives more or less the same. still good one there. – shirish Apr 20 '15 at 22:07
This answer is the best way. Tip: 1) xdg-mime query filetype FILE is the XDG way to find mime types. 2) You can also edit the defaults yourself to keep things more organized and back them up later: .config/mimeapps.list is the file. – Ciro Santilli 巴拿馬文件 六四事件 法轮功 Mar 20 at 10:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.