Difference between revisions of "Xdg-open"

From ArchWiki
Jump to: navigation, search
(update Pkg/AUR templates to reflect new package status)
m (Italics added.)
Line 1: Line 1:
 
[[Category:Desktop environments]]
 
[[Category:Desktop environments]]
 
{{lowercase title}}
 
{{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.
  
Inside a [[desktop environment]] (e.g. [[GNOME]], [[KDE]], or [[Xfce]]), {{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]], e.g. [[Openbox]]), {{ic|xdg-open}} will use its own configuration files.
+
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.
  
 
== 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. 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.
  
 
== Configuration ==
 
== Configuration ==
xdg-open uses the configuration file mentioned in [[Default Applications#Using MIME types and desktop entries]]. You can edit this file by using {{ic|xdg-mime}}.
+
 
 +
''xdg-open'' uses the configuration file mentioned in [[Default Applications#Using MIME types and desktop entries|Default Applications]]. You can edit this file by using ''xdg-mime''.
  
 
=== Examples ===
 
=== Examples ===
 +
 
==== get mime type ====
 
==== get mime type ====
 +
 
To get mime type of {{ic|photo.jpg}}:
 
To get mime type of {{ic|photo.jpg}}:
 
{{hc|$ xdg-mime query filetype photo.jpg|
 
{{hc|$ xdg-mime query filetype photo.jpg|
Line 19: Line 23:
 
}}
 
}}
  
==== get default application ====
+
==== Get default application ====
 +
 
 
To get default {{ic|.desktop}} file starter for {{ic|image/jpeg}} mime type:
 
To get default {{ic|.desktop}} file starter for {{ic|image/jpeg}} mime type:
 
{{hc|$ xdg-mime query default image/jpeg|
 
{{hc|$ xdg-mime query default image/jpeg|
Line 25: Line 30:
 
}}
 
}}
  
==== set the default file-browser ====
+
==== Set the default file-browser ====
To make Thunar the default file-browser, i.e. the default application for opening folders:
+
 
 +
To make Thunar the default file browser, i.e. the default application for opening folders:
 
  $ xdg-mime default Thunar.desktop inode/directory
 
  $ xdg-mime default Thunar.desktop inode/directory
  
==== set the default PDF viewer ====
+
==== Set the default PDF viewer ====
 +
 
 
To use {{AUR|xpdf}} as the default PDF viewer:
 
To use {{AUR|xpdf}} as the default PDF viewer:
 
  $ xdg-mime default xpdf.desktop application/pdf
 
  $ xdg-mime default xpdf.desktop application/pdf
  
==== set the default browser ====
+
==== Set the default browser ====
To set the default application for {{ic|http(s)://}} links (replace {{ic|''browser.desktop''}} by your browser's .desktop, e.g. {{ic|firefox.desktop}} or {{ic|chromium.desktop}}):
+
  $ xdg-mime default ''browser.desktop'' x-scheme-handler/http
+
  $ xdg-mime default ''browser.desktop'' x-scheme-handler/https
+
  
or
+
To set the default application for {{ic|http(s)://}} links (replace {{ic|''browser.desktop''}} by your browser's ''.desktop'', e.g. {{ic|firefox.desktop}} or {{ic|chromium.desktop}}):
  $ xdg-mime default ''browser.desktop'' text/html
+
$ xdg-mime default ''browser.desktop'' x-scheme-handler/http
 +
$ xdg-mime default ''browser.desktop'' x-scheme-handler/https
  
To test if this was applied successfully, try to open an URL with {{ic|xdg-open}} as follows:
+
or:
 +
$ xdg-mime default ''browser.desktop'' text/html
 +
 
 +
To test if this was applied successfully, try to open an URL with ''xdg-open'' as follows:
 
  $ xdg-open https://archlinux.org
 
  $ xdg-open https://archlinux.org
  
Line 51: Line 59:
 
! Name/Package !! Description !! Based on !! Configuration file
 
! Name/Package !! Description !! Based on !! Configuration file
 
|-
 
|-
| {{AUR|busking-git}} || A simple, regex-based xdg-open replacement. || {{pkg|perl-file-mimeinfo}} || custom
+
| {{AUR|busking-git}} || A simple, regex-based xdg-open replacement. || {{Pkg|perl-file-mimeinfo}} || custom
 
|-
 
|-
| {{AUR|expro}} || Opens objects in associated applications by matching regular expressions against object name or MIME-type. || {{pkg|file}} (but alternatives can be configured) || custom
+
| {{AUR|expro}} || Opens objects in associated applications by matching regular expressions against object name or MIME-type. || {{Pkg|file}} (but alternatives can be configured) || custom
 
|-
 
|-
| {{AUR|linopen}} || An intelligent and suckless replacement for xdg-open. || {{pkg|file}} || custom
+
| {{AUR|linopen}} || An intelligent and suckless replacement for xdg-open. || {{Pkg|file}} || custom
 
|-
 
|-
| {{AUR|mimeo}} || Open files by MIME-type or file name using regular expressions. It can be used on its own or through {{AUR|xdg-utils-mimeo}}. || {{pkg|file}} || standard {{ic|mimeapps.list}} or {{ic|defaults.list}}; custom is optional
+
| {{AUR|mimeo}} || Open files by MIME-type or file name using regular expressions. It can be used on its own or through {{AUR|xdg-utils-mimeo}}. || {{Pkg|file}} || standard {{ic|mimeapps.list}} or {{ic|defaults.list}}; custom is optional
 
|-
 
|-
| {{AUR|mimi-git}} || A working replacement for xdg-open. || {{pkg|file}} || custom
+
| {{AUR|mimi-git}} || A working replacement for xdg-open. || {{Pkg|file}} || custom
 
|}
 
|}
  
===run-mailcap===
+
=== 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:
+
 
 +
The ''.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
 
  #!/bin/sh
 
  run-mailcap $1 || mimeo $1
 
  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.
+
Then use the {{ic|defaults.list}} at {{ic|~/.local/share/applications/}} to associate URLs and folders with applications and the ''.mailcap'' file for normal mimetypes.
  
 
=== mimetype  ===
 
=== mimetype  ===
mimetype in {{Pkg|perl-file-mimeinfo}} package can display some mimetype-related information about a file.
+
 
 +
''mimetype'' in {{Pkg|perl-file-mimeinfo}} package can display some mimetype-related information about a file.
  
 
For example:
 
For example:
Line 84: Line 94:
  
 
=== Environment variables ===
 
=== 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.
+
 
 +
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.
  
 
== See also ==
 
== See also ==
 +
 
* [[Default Applications]] - Desktop-specific instructions/overview of alternatives to xdg-open
 
* [[Default Applications]] - Desktop-specific instructions/overview of alternatives to xdg-open
 
* [[Environment Variables]]
 
* [[Environment Variables]]

Revision as of 13:56, 13 November 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, 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.

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

xdg-open uses the configuration file mentioned in Default Applications. You can edit this file by using xdg-mime.

Examples

get mime type

To get mime type of photo.jpg:

$ xdg-mime query filetype photo.jpg
photo.jpg
    image/jpeg

Get default application

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

$ xdg-mime query default image/jpeg
gpicview.desktop;

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

To set the default application for http(s):// links (replace browser.desktop by your browser's .desktop, e.g. firefox.desktop or chromium.desktop):

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

or:

$ xdg-mime default browser.desktop text/html

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

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