Default applications (简体中文)

Programs sometimes need to open a file or a URI in the user's preferred application. To open a file in the user's preferred application the filetype needs to be detected (usually using filename extensions or magic numbers mapped to MIME types) and there needs to be an application associated with the filetype.

翻译状态:本文是 Default applications翻译。上次翻译日期:2018-07-03。如果英文版本有所更改,则您可以帮助同步翻译。

Freedesktop.org has standardized filetype detection with the Shared MIME database specification and application association with the XDG MIME Applications specification.

Some desktop environments also provide a GUI or a file-manager which can interactively configure default applications. If you do not use a desktop environment, you may need to install additional software in order to conveniently manage default applications.

Resource openers

  • XDG MIME Apps: implements the XDG MIME Applications specification
  • RegEx rules: allows MIME types to be associated with applications using regular expressions
  • URI support: allows arbitrary URI schemes to be associated with applications
NamePackageXDG MIME AppsRegEx rulesURI support
xdg-openxdg-utils
mimeopen(1p)perl-file-mimeinfo
mimeo
whippet
linopen
mimimimi-gitAUR
buskingbusking-gitAUR
sx-open
ranger

xdg-open

xdg-open (part of xdg-utils) implements XDG MIME Applications and is used by many programs.

Because of the complexity of the xdg-utils version of xdg-open, it can be difficult to debug when the wrong default application is being opened. Because of this, there are many alternatives that attempt to improve upon it. Several of these alternatives replace the executable, thus changing the default application behavior of most applications. Others simply provide an alternative method of choosing default applications.

perl-file-mimeinfo

perl-file-mimeinfo provides the tools mimeopen(1p) and . These have a slightly nicer interface than their equivalents:

# determine a file's MIME type
$ mimetype photo.jpeg
photo.jpeg: image/jpeg

# choose the default application for this file
$ mimeopen -d photo.jpeg
Please choose an application

    1) Feh (feh)
    2) GNU Image Manipulation Program (gimp)
    3) Pinta (pinta)

use application #

# open a file with its default application
$ mimeopen -n photo.jpeg

Most importantly, xdg-utils programs will actually call instead of for MIME type detection, if it does not detect your desktop environment. This is important because does not follow the XDG standard.

注意: perl-file-mimeinfo before 0.28-1 does not entirely follow the XDG standard. For example it does not read distribution-wide defaults and it saves its config in deprecated locations.

mimeo

provides the tool , which unifies the functionality of  and .
# determine a file's MIME type
$ mimeo -m photo.jpeg
photo.jpeg
  image/jpeg

# choose the default application for this MIME type
$ mimeo --add image/jpeg feh.desktop

# open a file with its default application
$ mimeo photo.jpeg

However a big difference with xdg-utils is that mimeo also supports custom "association files" that allow for more complex associations. For example, passing specific command line arguments based on a regular expression match:

# open youtube links in VLC without opening a new instance
vlc --one-instance --playlist-enqueue %U
  ^https?://(www.)?youtube.com/watch\?.*v=
patches xdg-utils so that  falls back to mimeo if no desktop environment is detected.

whippet

provides the tool whippet, which is similar to . It has X11 integration by using  to display errors and  to display choices between applications to open.
# open a file with its default application
$ whippet -M photo.jpeg

# choose from all possible applications for opening a file (without setting a default)
$ whippet -m photo.jpeg

In addition to implementing XDG MIME Applications, whippet can also use a SQlite database of weighted application/MIME type/regex associations to determine which app to use.

Minimalist replacements

The following packages conflict with and provide because they provide their own script.

If you want to use one of these resource openers while still being able to use , install them manually in a PATH directory before /usr/bin.

  • - 170-line Bash script, supports regex rules
  • mimi-gitAUR - 130-line Bash script, can change command arguments for each MIME type
  • busking-gitAUR - 80-line Perl script similar to mimi but also supports regex rules
  • - 60-line Bash script, uses a simple shell-based config file
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.