「デフォルトアプリケーション」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(序文を翻訳)
3行目: 3行目:
 
[[ru:Default applications]]
 
[[ru:Default applications]]
 
[[zh-hans:Default applications]]
 
[[zh-hans:Default applications]]
プログラムはさまざまな方法でデフォルトのアプリケーションの関連付けを実装します。コマンドラインプログラムは伝統的に[[環境変数#デフォルトプログラム|環境変数]]を使が、グラフィカルアプリケーションでは、[[Wikipedia:GIO (software)|GIO]] API、[[Qt]] API または [[xdg-utils]] の一部である {{ic|/usr/bin/xdg-open}} を実行することで、[[XDG MIME Applications]] を使用する傾向があります。[[xdg-open]] や [[XDG MIME Applications]] は非常に複雑なので、様々な代替リソースオープナーが開発されました。次の表は、それぞれの方法のアプリケーション例です。
+
プログラムはさまざまな方法でデフォルトのアプリケーションの関連付けを実装します。コマンドラインプログラムは伝統的に[[環境変数#デフォルトプログラム|環境変数]]を使いますが、グラフィカルアプリケーションでは、[[Wikipedia:GIO (software)|GIO]] API、[[Qt]] API または [[xdg-utils]] の一部である {{ic|/usr/bin/xdg-open}} を実行することで、[[XDG MIME Applications]] を使用する傾向があります。[[xdg-open]] や [[XDG MIME Applications]] は非常に複雑なので、様々な代替リソースオープナーが開発されました。次の表は、それぞれの方法のアプリケーション例です。
   
 
{| class=wikitable
 
{| class=wikitable
  +
! メソッド !! XDG を使用 !! アプリケーション例
! Method !! Uses XDG !! Application examples
 
 
|-
 
|-
 
| [https://developer.gnome.org/gio/stable/GAppInfo.html GIO's GAppInfo] || Yes || [[Firefox]], [[GNOME Files]], [[PCManFM]], [[Thunar]], [[Thunderbird]], [[Telegram]]
 
| [https://developer.gnome.org/gio/stable/GAppInfo.html GIO's GAppInfo] || Yes || [[Firefox]], [[GNOME Files]], [[PCManFM]], [[Thunar]], [[Thunderbird]], [[Telegram]]
 
|-
 
|-
| {{ic|/usr/bin/xdg-open}} || By default || [[Chromium]] (Open downloaded file)
+
| {{ic|/usr/bin/xdg-open}} || By default || [[Chromium]] (ダウンロードしたファイルを開く)
 
|-
 
|-
 
| custom || Usually not || [[mc]], [[ranger]]
 
| custom || Usually not || [[mc]], [[ranger]]
16行目: 16行目:
 
| [[環境変数#デフォルトプログラム|環境変数]] || No || [[man]], [[sudoedit]], [[systemctl]]
 
| [[環境変数#デフォルトプログラム|環境変数]] || No || [[man]], [[sudoedit]], [[systemctl]]
 
|-
 
|-
| [[D-Bus]]'s FileManager1 || org.freedesktop.FileManager1 || [[Firefox]] (Open containing folder), Zotero (Show file), [[Telegram]] (Show in folder)
+
| [[D-Bus]] FileManager1 || org.freedesktop.FileManager1 || [[Firefox]] (Open containing folder), Zotero (ファイルを表示), [[Telegram]] (フォルダに表示)
 
|}
 
|}
   
Many [[デスクトップ環境]]s and graphical [[ファイルマネージャ]] provide a GUI for configuring default applications.
+
多くの[[デスクトップ環境]]とグラフィカル[[ファイルマネージャ]]は、デフォルトのアプリケーションを設定するための GUI を提供します。
   
 
== Background information ==
 
== Background information ==

2021年8月14日 (土) 10:10時点における版

プログラムはさまざまな方法でデフォルトのアプリケーションの関連付けを実装します。コマンドラインプログラムは伝統的に環境変数を使いますが、グラフィカルアプリケーションでは、GIO API、Qt API または xdg-utils の一部である /usr/bin/xdg-open を実行することで、XDG MIME Applications を使用する傾向があります。xdg-openXDG MIME Applications は非常に複雑なので、様々な代替リソースオープナーが開発されました。次の表は、それぞれの方法のアプリケーション例です。

メソッド XDG を使用 アプリケーション例
GIO's GAppInfo Yes Firefox, GNOME Files, PCManFM, Thunar, Thunderbird, Telegram
/usr/bin/xdg-open By default Chromium (ダウンロードしたファイルを開く)
custom Usually not mc, ranger
環境変数 No man, sudoedit, systemctl
D-Bus の FileManager1 org.freedesktop.FileManager1 Firefox (Open containing folder), Zotero (ファイルを表示), Telegram (フォルダに表示)

多くのデスクトップ環境とグラフィカルファイルマネージャは、デフォルトのアプリケーションを設定するための GUI を提供します。

Background information

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.

Heirloom UNIX programs used mime.types for MIME type detection and mailcap for application association.

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
Name Package XDG MIME Apps RegEx rules URI support
xdg-open xdg-utils Yes No Yes
mimeopen(1p) perl-file-mimeinfo Yes No No
mimeo mimeoAUR Yes Yes Yes
whippet whippetAUR Yes No Yes
linopen linopenAUR No Yes Yes
mimi mimi-gitAUR No No partly
busking busking-gitAUR No Yes Yes
sx-open sx-openAUR No Yes Yes
rifle(1) ranger No Yes No
handlr handlr-binAUR Yes No Yes

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 /usr/bin/xdg-open 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 mimetype(1p). These have a slightly nicer interface than their xdg-utils 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 file instead of mimetype for MIME type detection if it does not detect your デスクトップ環境. This is important because file does not follow the XDG standard.

ノート: perl-file-mimeinfo before 0.28-1 did not entirely follow the XDG standard. For example it did not not read distribution-wide defaults and it saved its config in deprecated locations.

mimeo

mimeoAUR provides the tool mimeo, which unifies the functionality of xdg-open and xdg-mime.

# 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=

xdg-utils-mimeoAUR patches xdg-utils so that xdg-open falls back to mimeo if no desktop environment is detected.

whippet

whippetAUR provides the tool whippet, which is similar to xdg-open. It has X11 integration by using libnotify to display errors and dmenu 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.

handlr

handlr-binAUR, written in Rust, provides the functionality of xdg-open and xdg-mime with a streamlined interface.

Compared to xdg-utils, it includes:

  • setting associations by extension, removing the need to look up or remember mime types
  • validation for mime types and extensions
  • removal of invalid entries from mimeapps.list
  • intelligent detection of mime types from file content in case filename is ambiguous
  • autocompletion of mimes, extensions, and desktop entries
# The following two are identical
handlr set .png feh.desktop
handlr set image/png feh.desktop

# List default apps
handlr list

# Get the handler for a mime/extension
$ handlr get .png --json
{"handler":"pqiv.desktop","name":"pqiv","cmd":"/usr/bin/pqiv"}

# Launch a handler with optional path/URL
handlr launch x-scheme-handler/https
handlr launch x-scheme-handler/https -- https://google.ca

xdg-utils-handlrAUR provides an xdg-open that uses handlr under the hood to replace xdg-utils.

Minimalist replacements

The following packages conflict with and provide xdg-utils because they provide their own /usr/bin/xdg-open script.

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

  • linopenAUR - 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
  • sx-openAUR - 60-line Bash script, uses a simple shell-based config file

run-mailcap

警告: If you use run-mailcapAUR, it is possible for xdg-open to delegate to it. This will cause an infinite loop if you are using the /etc/mailcap from mailcap, because it also delegates to xdg-open.