Difference between revisions of "Xdg-open"

From ArchWiki
Jump to: navigation, search
(xdg-open replacements: add note on hardcoded absolute xdg-open path)
(xdg-open replacements: some repetition for clarity)
Line 94: Line 94:
{{Note|The above replacements can be symbolically linked to ''xdg-open''  above {{ic|/usr/bin}} in the user's {{ic|$PATH}} (for example, {{ic|ln -s /usr/bin/sx-open /usr/local/bin/xdg-open}}). However, applications may hard-code the absolute path {{ic|/usr/bin/xdg-open}}. In this case, install {{AUR|xdg-utils-no-open}} from the [[AUR]] and copy the replacement to that location.}}
{{Note|The above replacements can be symbolically linked to ''xdg-open''  above {{ic|/usr/bin}} in the user's {{ic|$PATH}} (for example, {{ic|ln -s /usr/bin/sx-open /usr/local/bin/xdg-open}}). However, applications may hard-code the absolute path {{ic|/usr/bin/xdg-open}}. In this case, install {{AUR|xdg-utils-no-open}} from the [[AUR]] and copy the replacement to {{ic|/usr/bin/xdg-open}}.}}
=== mailcap ===
=== mailcap ===

Revision as of 16:52, 4 February 2015

Merge-arrows-2.pngThis article or section is a candidate for merging with Default applications.Merge-arrows-2.png

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, or Xfce), 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 the official repositories. It is for use inside a desktop session only, and should not be run as root.

If you run xdg-open without a desktop environment, you should also install perl-file-mimeinfo, or xdg-utils-mimeoAUR and mimeoAUR from the AUR for a faster alternative.


xdg-open is configured by the files mentioned in Default applications. xdg-mime modifies the local file ~/.local/share/applications/mimeapps.list.

To query the mime type used by an existing file, use xdg-mime query filetype file.ext. Reversely, to query the default desktop entry associated to a specific mime type, run xdg-mime query default mime/type. Common types include inode/directory (file browser), image/jpeg (JPEG images), and application/pdf (PDF viewer).

To change an associated desktop entry, use xdg-mime default application.desktop mime/type. To for example set Thunar as the default file browser, run:

$ xdg-mime default Thunar.desktop inode/directory

This command can take multiple mime-types, allowing related files to be handled by the same program. The example below associates Emacs to all known source files:

$ xdg-mime default emacs.desktop $(grep '^text/x-*' /usr/share/mime/types)

Set the default browser

Tango-inaccurate.pngThe factual accuracy of this article or section is disputed.Tango-inaccurate.png

Reason: There are many more MIME types for browsers (Discuss in Talk:Xdg-open#)

To set the default application for http(s):// links:

$ xdg-mime default browser.desktop x-scheme-handler/http
$ xdg-mime default browser.desktop x-scheme-handler/https

To do so for .html files:

$ xdg-mime default browser.desktop text/html

Alternatively, run:

$ xdg-settings set default-web-browser browser.desktop

To test if this was applied successfully, try to open an URL with xdg-open as follows:

$ xdg-open https://archlinux.org


xdg-open uses perl-file-mimeinfo as a fallback ("generic") method if no desktop environment is detected. It can be invoked directly with:

$ mimeopen -d /path/to/file

You are asked which application to use when opening /path/to/file:

Please choose a default application for files of type text/plain
       1) notepad  (wine-extension-txt)
       2) Leafpad  (leafpad)
       3) OpenOffice.org Writer  (writer)
       4) gVim  (gvim)
       5) Other...

Your answer becomes the default handler for that type of file. Mimeopen is installed as /usr/bin/perlbin/vendor/mimetype.

Drop-in replacements and useful tools

xdg-open replacements

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: There may be some benefit to making this a table, but Template:App including upstream URLs gives all needed information in a simple manner (Discuss in Talk:Xdg-open#)
Name/Package Method Based on Configuration file
busking-gitAUR Regular expressions perl-file-mimeinfo custom
linopenAUR file custom
mimeoAUR MIME-type, regular expressions file mimeapps.list, defaults.list; custom is optional
mimi-gitAUR file custom
easeAUR MIME-type, name, regular expressions SQLite database or file, perl-file-mimeinfo, etc custom SQLite database or mimeapps.list
ayrAUR MIME-type, name, regular expressions file or perl-file-mimeinfo, etc mimeapps.list, defaults.list
sx-open Regular expressions file, bash regex custom
Note: The above replacements can be symbolically linked to xdg-open above /usr/bin in the user's $PATH (for example, ln -s /usr/bin/sx-open /usr/local/bin/xdg-open). However, applications may hard-code the absolute path /usr/bin/xdg-open. In this case, install xdg-utils-no-openAUR from the AUR and copy the replacement to /usr/bin/xdg-open.


The .mailcap file format is used by mail programs such as mutt and sylpheed. To have those programs use xdg-open, edit ~/.mailcap:

*/*; xdg-open "%s


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.

When xdg-open fails to detect one of the desktop environments it knows about, it normally falls back to using file -i, which uses only file contents to determine the mimetype, resulting in some file types not being detected correctly. With mimetype available, xdg-open will use that instead, with better detection results, as mimetype uses the information in the shared mime info database.

Environment variables

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