Difference between revisions of "Xdg-open"

From ArchWiki
Jump to: navigation, search
(Setting the default browser for xdg-open: request merging subsections)
(lowercase title)
Line 1: Line 1:
 
[[Category:Desktop environments]]
 
[[Category:Desktop environments]]
 +
{{lowercase title}}
 
xdg-open is a desktop-independent tool for configuring the default applications of a user. Many applications invoke the {{ic|xdg-open}} command internally.
 
xdg-open is a desktop-independent tool for configuring the default applications of a user. Many applications invoke the {{ic|xdg-open}} command internally.
  

Revision as of 16:06, 31 October 2013

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.

Installation

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.

Configuration

The config file

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

Notes: Default Applications article describes (or at least should describe) the standard in general, as well as manual method of configuration (Discuss in Talk:Xdg-open#)

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

[Default Applications]
mimetype=desktopfile1;desktopfile2...

For example:

[Default Applications]
text/html=firefox.desktop
inode/directory=kde4-dolphin.desktop;Thunar.desktop;nautilus.desktop

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:

xdg-mime

  • To get mime type of photo.jpg:
    $ xdg-mime query filetype photo.jpg
    photo.jpg
        image/jpeg
    
  • To get default .desktop file starter for image/jpeg mime type:
    $ xdg-mime query default image/jpeg
    gpicview.desktop;
    
  • 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

    Previous command should create an entry in your local MIME database like this:

    ~/.local/share/applications/mimeapps.list
    [Default Applications]
    application/pdf=xpdf.desktop

Setting the default browser for xdg-open

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

Reason: The following subsections should be merged, there is no difference between Firefox and Chromium (and other browsers) in terms of configuring default browser. (Discuss in Talk:Xdg-open#)
Firefox

This can be tricky to find, so to save you some work, type the following commands:

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

or

 $ xdg-mime default firefox.desktop text/html
Chromium
  • The simplest way to make Chromium the default browser is to set the BROWSER environment variable:
    ~/.profile
    if [ -n "$DISPLAY" ]; then
        BROWSER=chromium
    fi

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

    $ xdg-open http://google.com
    

    If everything went well, either a new tab inside Chromium, or a new window would open and display the Google homepage, depending on your settings.

  • Another option, if you are using mimeoAUR, is to associate http:// links with Chromium:
    ~/.config/mimeo.conf
    /usr/bin/chromium
      ^http://
  • If all of the previous configurations still do not get it working, you can try the following:
    ~/.local/share/applications/mimeapps.list
    [Added Associations]
    [...]
    x-scheme-handler/http=chromium.desktop
    
    [Default Applications]
    [...]
  • If even that didn't work, try this:
    $ xdg-mime default chromium.desktop x-scheme-handler/http
    $ xdg-mime default chromium.desktop x-scheme-handler/https

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

run-mailcap

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:

#!/bin/sh
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

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.

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.

See also