Difference between revisions of "Xdg-open"

From ArchWiki
Jump to: navigation, search
(Set the default browser)
(already mention mimeo here as it has a significant performance benefit)
Line 12: Line 12:
== Installation ==
== Installation ==
''xdg-open'' is part of the {{Pkg|xdg-utils}} package available in the [[official repositories]]. ''xdg-open'' is for use inside a desktop session only. If you run ''xdg-open'' without a desktop environment, you should also install {{Pkg|perl-file-mimeinfo}}. It is not recommended to use ''xdg-open'' as root.
''xdg-open'' is part of the {{Pkg|xdg-utils}} package available in the [[official repositories]]. ''xdg-open'' is for use inside a desktop session only. It is not recommended to use ''xdg-open'' as root.
If you run ''xdg-open'' without a desktop environment, you should also install {{Pkg|perl-file-mimeinfo}}, or {{AUR|xdg-utils-mimeo}} and {{AUR|mimeo}} from the [[AUR]] for a faster alternative.
== Configuration ==
== Configuration ==

Revision as of 23:57, 24 September 2014

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. xdg-open is for use inside a desktop session only. It is not recommended to use xdg-open 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 uses the configuration file mentioned in Default applications. You can edit this file by using xdg-mime.


Get mime type

To get mime type of photo.jpg:

$ xdg-mime query filetype photo.jpg

Get default application

To get default .desktop file starter for image/jpeg mime type:

$ xdg-mime query default image/jpeg

Set the default file-browser

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

$ xdg-mime default Thunar.desktop inode/directory

Set the default PDF viewer

To use xpdfAUR as the default PDF viewer:

$ xdg-mime default xpdf.desktop application/pdf

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

Drop-in replacements and useful tools

xdg-open replacements

Name/Package Description Based on Configuration file
busking-gitAUR A simple, regex-based xdg-open replacement. perl-file-mimeinfo custom
exproAUR Opens objects in associated applications by matching regular expressions against object name or MIME-type. file (but alternatives can be configured) custom
linopenAUR An intelligent and suckless replacement for xdg-open. file custom
mimeoAUR Open files by MIME-type or file name using regular expressions. It can be used on its own or through xdg-utils-mimeoAUR. file standard mimeapps.list or defaults.list; custom is optional
mimi-gitAUR A working replacement for xdg-open. file custom
ayrAUR Manages menus of application launchers, either executables or desktop files. Also opens files and URIs with launchers, desktop files, or applications associated by name or MIME-type. Can use a wrapper script to replace xdg-open. file and/or perl-file-mimeinfo; other alternatives and fallbacks can be configured. XDG standard mimeapps.list and mimeinfo.cache (and the older defaults.list) to determine MIME-type associations. Optionally can also use regular expressions to match file or URI names to applications.


The .mailcap file format used by the mutt mail program is way easier to read and write. The run-mailcapAUR 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.

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.