Difference between revisions of "Xdg-open"

From ArchWiki
Jump to: navigation, search
m
(Added commands for setting default browser)
(36 intermediate revisions by 13 users not shown)
Line 1: Line 1:
[[Category:Desktop environments (English)]]
+
[[Category:Desktop environments]]
[[Category:Software (English)]]
+
xdg-open is a desktop-independent tool for configuring the default applications of a user. Many applications invoke the {{Ic|xdg-open}} command internally.
{{i18n|xdg-open}}
+
{{Expansion}}
+
  
xdg-open is a desktop-independent tool for configuring the default applications of a user. Many applications invoke the {{Codeline|xdg-open}} command internally.
+
Inside a [[Desktop Environment|desktop environment]] (e.g. [[GNOME]], [[KDE]], [[Xfce]], etc.), {{ic|xdg-open}} simply passes the arguments to that desktop environment's file-opener application ({{ic|gvfs-open}}, {{ic|kde-open}}, or {{ic|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|window manager]], e.g. [[Openbox]]), {{ic|xdg-open}} will use its own configuration files.
  
==Installation==
+
== Installation ==
xdg-open is part of the xdg-utils package available in extra:
+
xdg-open is part of the {{pkg|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.
  
pacman -S xdg-utils
+
== Configuration ==
 
+
=== The config file ===
==Configuration==
+
{{ic|xdg-open}} uses configuration files located at {{ic|$XDG_DATA_HOME/applications/mimeapps.list}} (for a single user; {{ic|$XDG_DATA_HOME}} defaults to {{ic|~/.local/share}}) and {{ic|/usr/share/applications/defaults.list}} (system wide). Its format is as follows:
You can bind mimetypes to .desktop files in {{filename|/usr/share/applications}} and {{filename|~/.local/share/applications}} with the xdg-mime command:
+
 
+
# This will make Thunar the default file-browser, i.e. the default application for opening folders.
+
xdg-mime default Thunar.desktop inode/directory
+
 
+
The best way to look up the MIME type is to read the {{Codeline|MimeTypes}} list in your application's {{filename|.desktop}} file.
+
 
+
===The config file===
+
{{Codeline|xdg-mime}} saves the configuration for {{Codeline|xdg-open}} in {{filename|~/.local/share/applications/defaults.list}}. Its format is as follows:
+
 
  [Default Applications]
 
  [Default Applications]
 
  mimetype=desktopfile1;desktopfile2...
 
  mimetype=desktopfile1;desktopfile2...
Line 28: Line 17:
 
  inode/directory=kde4-dolphin.desktop;Thunar.desktop;nautilus.desktop
 
  inode/directory=kde4-dolphin.desktop;Thunar.desktop;nautilus.desktop
  
It seems that it is perfectly save to edit that file.
+
The best way to look up the MIME type is to read the {{ic|MimeTypes}} list in your application's {{ic|.desktop}} file (see [[Desktop Entries]] for details).
 +
 
 +
Some tools are available to edit the configuration files:
 +
 
 +
=== xdg-mime ===
 +
To make Thunar the default file-browser, i.e. the default application for opening folders.
 +
 
 +
$ xdg-mime default Thunar.desktop inode/directory
 +
 
 +
to use {{pkg|xpdf}} as the default PDF viewer:
 +
$ xdg-mime default xpdf.desktop application/pdf
 +
 
 +
This should create an entry in your local MIME database:
 +
{{hc|~/.local/share/applications/defaults.list|<nowiki>
 +
[Default Applications]
 +
application/pdf=xpdf.desktop
 +
</nowiki>}}
 +
Your PDF files should be opened with {{pkg|xpdf}} now.
 +
 
 +
==== Setting default browser for xdg-open ====
 +
This can be tricky to find, so to save you some work:
 +
 
 +
  $ xdg-mime default firefox.desktop x-scheme-handler/http
 +
  $ xdg-mime default firefox.desktop x-scheme-handler/https
 +
 
 +
==Drop-in replacements and useful tools==
 +
 
 +
=== xdg-open replacements ===
 +
 
 +
{| class="wikitable"
 +
! Name/Package !! Description !! Based on
 +
|-
 +
| {{AUR|busking-git}} || A simple, regex-based xdg-open replacement. || {{pkg|perl-file-mimeinfo}}
 +
|-
 +
| {{AUR|expro}} || Opens objects in associated applications by matching regular expressions against object name or MIME-type. || {{pkg|file}} (but alternatives can be configured)
 +
|-
 +
| {{AUR|linopen}} || An intelligent and suckless replacement for xdg-open. || {{pkg|file}}
 +
|-
 +
| {{AUR|mimeo}} || Open files by MIME-type or file name using regular expressions. Also requires {{AUR|xdg-utils-mimeo}}. || {{pkg|file}}
 +
|-
 +
| {{AUR|mimi}} || A working replacement for xdg-open. || {{pkg|file}}
 +
|}
 +
 
 +
===run-mailcap===
 +
The {{ic|.mailcap}} file format used by the mutt mail program is way easier to read and write. The {{AUR|run-mailcap}} package from the AUR provides a executable that could be easily symlinked to {{ic|/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 {{ic|/usr/bin/xdg-open}} with the following content:
 +
 
 +
  #!/bin/sh
 +
  run-mailcap $1 || mimeo $1
 +
 
 +
Then use the {{ic|defaults.list}} at {{ic|~/.local/share/applications/}} to associate URLs and folders with applications and the {{ic|.mailcap}} file for normal mimetypes.
 +
 
 +
=== mimetype  ===
 +
mimetype in {{pkg|perl-file-mimeinfo}} package can display some mimetype-related information about a file.
 +
 
 +
For example:
  
If you want to set your default applications system-wide, copy this file to {{filename|/usr/share/applications}}
+
$ mimetype file.ext
  
===Environment Variables===
+
returns the mimetype of a file,
  
  export BROWSER=chromium # this will make xdg-open use chromium for any kind of URLs
+
  $ mimetype -d file.extension
  
export DE="xfce" # This will make xdg-open use the more user-friendly exo-open, because it assumes it is inside Xfce. Use exo-preferred-applications for configuring.
+
returns a description of that mimetype.
  
==See also==
+
=== Environment Variables ===
 +
Some environment variables, such as {{ic|BROWSER}}, {{ic|DE}}, and {{ic|DESKTOP_SESSION}}, will change the behaviour of the default xdg-open. See [[Environment Variables]] for more information.
  
* [[Default Applications]]
+
== See also ==
 +
* [[Default Applications]] - desktop-specific instructions/overview of alternatives to xdg-open
 +
* [[Environment Variables]]

Revision as of 00:26, 18 February 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 [extra]. xdg-open is for use inside a desktop session only. It is not recommended to use xdg-open as root.

Configuration

The config file

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

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

Your PDF files should be opened with xpdf now.

Setting default browser for xdg-open

This can be tricky to find, so to save you some work:

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

Drop-in replacements and useful tools

xdg-open replacements

Name/Package Description Based on
busking-gitAUR A simple, regex-based xdg-open replacement. perl-file-mimeinfo
exproAUR Opens objects in associated applications by matching regular expressions against object name or MIME-type. file (but alternatives can be configured)
linopenAUR An intelligent and suckless replacement for xdg-open. file
mimeoAUR Open files by MIME-type or file name using regular expressions. Also requires xdg-utils-mimeoAUR. file
mimiAUR A working replacement for xdg-open. file

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