Difference between revisions of "Xdg-open"

From ArchWiki
Jump to navigation Jump to search
m (→‎The config file: spelling)
Line 9: Line 9:
== Configuration ==
== Configuration ==
=== The config file ===
=== The config file ===
{{ic|xdg-open}} use configuration files located at {{ic|~/.local/share/applications/defaults.list}}(for a single user) and {{ic|/usr/share/applications/defaults.list}} (system wide). Its format is as follows:
{{ic|xdg-open}} uses configuration files located at {{ic|~/.local/share/applications/defaults.list}}(for a single user) and {{ic|/usr/share/applications/defaults.list}} (system wide). Its format is as follows:
  [Default Applications]
  [Default Applications]

Revision as of 21:23, 21 August 2012

xdg-open is a desktop-independent tool for configuring the default applications of a user. Many applications invoke the xdg-open command internally.

Inside a desktop environment (e.g. GNOME, KDE, Xfce, etc.), xdg-open simply passes the arguments to that desktop environment's file-opener application (gvfs-open, kde-open, or exo-open, respectively), which means that the associations are left up to the desktop environment. When no desktop environment is detected (for example when one runs a standalone window manager, e.g. Openbox), xdg-open will use its own configuration files.


xdg-open is part of the xdg-utils package available in [extra]. xdg-open is for use inside a desktop session only. It is not recommended to use xdg-open as root.


The config file

xdg-open uses configuration files located at ~/.local/share/applications/defaults.list(for a single user) and /usr/share/applications/defaults.list (system wide). Its format is as follows:

[Default Applications]

For example,

[Default Applications]

The best way to look up the MIME type is to read the MimeTypes list in your application's .desktop file (see Desktop Entries for details).

Some tools are available to edit the configuration files:


To make Thunar the default file-browser, i.e. the default application for opening folders.

$ xdg-mime default Thunar.desktop inode/directory

to use xpdf as the default PDF viewer:

$ xdg-mime default xpdf.desktop application/pdf

This should create an entry in your local MIME database:

[Default Applications]

Your PDF files should be opened with xpdf now.

Drop-in replacements and useful tools


The .mailcap file format used by the mutt mail program is way easier to read and write. The run-mailcap package from the AUR provides a executable that could be easily symlinked to /usr/bin/xdg-open, but that parser is unable to handle directories or links. The simplest solution would be to install mimeo from the AUR too and create a /usr/bin/xdg-open with the following content:

  run-mailcap $1 || mimeo $1

Then use the defaults.list at ~/.local/share/applications/ to associate URLs and folders with applications and the .mailcap file for normal mimetypes.


mimetype in perl-file-mimeinfo package can display some mimetype-related information about a file.

For example:

$ mimetype file.ext

returns the mimetype of a file,

$ mimetype -d file.extension

returns a description of that mimetype.


mimeoAUR and xdg-utils-mimeoAUR in AUR provide xdg-utils and contains a xdg-open script patched to make use of mimeo the same way gnome-open would be used. Mimetype<->application associations can then be customised easily in $XDG_CONFIG_HOME/mimeo.conf (i.e.~/.config/mimeo.conf)

Environment Variables

Some environment variables such as BROWSER, DE and DESKTOP_SESSION will change behaviour of xdg-open. See Environment Variables for more information.

See also