「XDG MIME Applications」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(デフォルトアプリケーション絡みの記事が古くなっているため、英語版からコピー。)
 
(→‎書式: 訳を修正)
 
(2人の利用者による、間の23版が非表示)
2行目: 2行目:
 
[[en:XDG MIME Applications]]
 
[[en:XDG MIME Applications]]
 
[[ru:XDG MIME Applications]]
 
[[ru:XDG MIME Applications]]
[[zh-hans:Default applications]]
 
 
{{Related articles start}}
 
{{Related articles start}}
 
{{Related|デスクトップエントリ}}
 
{{Related|デスクトップエントリ}}
10行目: 9行目:
 
{{Related|xdg-utils}}
 
{{Related|xdg-utils}}
 
{{Related articles end}}
 
{{Related articles end}}
The [https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html XDG MIME Applications specification] builds upon the [[#Shared MIME database|shared MIME database]] and [[デスクトップエントリ]] to provide [[デフォルトアプリケーション]].
+
[https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-latest.html XDG MIME Applications specification] [[デフォルトアプリケーション]] を用意するために [[#共有 MIME データベース|共有 MIME データベース]] [[デスクトップエントリ]] から成り立っています。
   
# Applications describe what MIME types they can handle using [[デスクトップエントリ]].
+
# XDG MIME Applications どの MIME type を扱うことができるかを [[デスクトップエントリ]] を使って定義します。
# {{Pkg|desktop-file-utils}} registers a [[pacman フック]] to build a cache database of MIME types handled by desktop entries, see {{man|1|update-desktop-database}}.
+
# {{Pkg|desktop-file-utils}} [[pacman フック]] であり、デスクトップエントリが扱う MIME type のデータベースを構築します。詳細は {{man|1|update-desktop-database}} を見て下さい。
  +
# XDG MIME Applications は {{ic|/usr/share/mime/packages/}} に XML ファイルを置くことにより新しい MIME タイプ をインストールできます。
# Applications can install new MIME types by placing XML files in {{ic|/usr/share/mime/packages/}}.
 
# {{Pkg|shared-mime-info}} registers a [[pacman フック]] to build the Shared MIME-Info database cache, see {{man|1|update-mime-database}}.
+
# {{Pkg|shared-mime-info}} Shared MIME-Info database cache を構築するために [[pacman フック]] を登録します。詳しくは {{man|1|update-mime-database}} を参照して下さい。
# [[デスクトップ環境]]s and users can change default applications and add or remove MIME type to application associations using [[#mimeapps.list|mimeapps.list]] files.
+
# [[デスクトップ環境]] とユーザーは [[#mimeapps.list|mimeapps.list]] ファイルを通じて特定の MIME タイプ に紐付くデフォルトアプリケーションの変更や設定、削除ができます。
   
== Shared MIME database ==
+
== 共有 MIME データベース ==
   
The [https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html XDG Shared MIME-info Database specification] facilitates a shared MIME database across desktop environments and allows applications to easily register new MIME types system-wide.
+
[https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html XDG Shared MIME-info Database specification] 仕様は、デスクトップ環境間での MIME データベースの共有を容易にし、アプリケーションがシステム全体で新しい MIME タイプを簡単に登録できるようにするものです。
   
The database is built from the XML files installed by packages in {{ic|/usr/share/mime/packages/}} using the tools from {{Pkg|shared-mime-info}}.
+
データベースは、{{ic|/usr/share/mime/packages/}} にあるパッケージによってインストールされた XML ファイルから {{Pkg|shared-mime-info}} のツールを使って構築されます。
   
  +
{{ic|/usr/share/mime/}} にあるファイルを直接編集してはいけませんが、 {{ic|~/.local/share/mime/}} ツリーにあるデータベースをユーザーごとに管理することは可能です。
The files in {{ic|/usr/share/mime/}} should not be directly edited, however it is possible to maintain a separate database on a per-user basis in the {{ic|~/.local/share/mime/}} tree.
 
   
"URI scheme handling [..] are handled through applications handling the {{ic|x-scheme-handler/foo}} MIME type, where foo is the URI scheme in question."[https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html#idm140625828587776]
+
URI スキームの処理 [...] は、{{ic|x-scheme-handler/foo}} MIME タイプを処理するアプリケーションを通して処理されます(foo は問題の URI スキーム)」[https://specifications.freedesktop.org/shared-mime-info-spec/shared-mime-info-spec-latest.html#idm140625828587776]
   
=== New MIME types ===
+
=== 新しい MIME タイプ ===
   
  +
この例では、新しい MIME タイプ {{ic|application/x-foobar}} を定義し、''.foo'' で終わる名前を持つすべてのファイルに割り当てています。単に次のようなファイルを作成します。
This example defines a new MIME type {{ic|application/x-foobar}} and assigns it to any file with a name ending in ''.foo''. Simply create the following file:
 
   
 
{{hc|~/.local/share/mime/packages/application-x-foobar.xml|2=
 
{{hc|~/.local/share/mime/packages/application-x-foobar.xml|2=
44行目: 43行目:
 
}}
 
}}
   
  +
次に、MIME データベースを更新します。
And then update the MIME database:
 
   
 
$ update-mime-database ~/.local/share/mime
 
$ update-mime-database ~/.local/share/mime
   
Of course this will not have any effect if no desktop entries are associated with the MIME type. You may need to create new [[デスクトップエントリ]] or modify [[#mimeapps.list|mimeapps.list]].
+
もちろん、デスクトップエントリが MIME タイプに関連付けられていない場合、これは効果がありません。新しい[[デスクトップエントリ]]を作成するか、[[#mimeapps.list|mimeapps.list]] を変更する必要がある場合があります。
   
 
== mimeapps.list ==
 
== mimeapps.list ==
   
The [https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.html XDG standard] is the most common for configuring desktop environments. Default applications for each MIME type are stored in {{ic|mimeapps.list}} files, which can be stored in several locations. They are searched in the following order, with earlier associations taking precedence over later ones:
+
[https://specifications.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.html XDG 標準]は、デスクトップ環境を設定するための最も一般的な規格です。各 MIME タイプのデフォルトのアプリケーションは、{{ic|mimeapps.list}} ファイルに格納されています。これらは以下の順序で検索され、先に関連づけられたものが後に関連づけられたものよりも優先されます。
   
 
{| class="wikitable"
 
{| class="wikitable"
 
! Path !! Usage
 
! Path !! Usage
 
|-
 
|-
| {{ic|~/.config/mimeapps.list}} || user overrides
+
| {{ic|~/.config/mimeapps.list}} || ユーザーオーバーライド
 
|-
 
|-
| {{ic|/etc/xdg/mimeapps.list}} || system-wide overrides
+
| {{ic|/etc/xdg/mimeapps.list}} || システム全体のオーバーライド
 
|-
 
|-
| {{ic|~/.local/share/applications/mimeapps.list}} || ('''deprecated''') user overrides
+
| {{ic|~/.local/share/applications/mimeapps.list}} || ('''非推奨''') ユーザーオーバーライド
 
|-
 
|-
| {{ic|/usr/local/share/applications/mimeapps.list}}<br>{{ic|/usr/share/applications/mimeapps.list}} || distribution-provided defaults
+
| {{ic|/usr/local/share/applications/mimeapps.list}}<br>{{ic|/usr/share/applications/mimeapps.list}} || ディストリビューション提供のデフォルト
 
|}
 
|}
   
Additionally, it is possible to define [[デスクトップ環境]]-specific default applications in a file named {{ic|''desktop''-mimeapps.list}} where {{ic|''desktop''}} is the name of the desktop environment (from the {{ic|XDG_CURRENT_DESKTOP}} environment variable). For example, {{ic|/etc/xdg/xfce-mimeapps.list}} defines system-wide default application overrides for [[Xfce]]. These desktop-specific overrides take precedence over the corresponding non-desktop-specific file. For example, {{ic|/etc/xdg/xfce-mimeapps.list}} takes precedence over {{ic|/etc/xdg/mimeapps.list}} but is still overridden by {{ic|~/.config/mimeapps.list}}.
+
さらに、[[デスクトップ環境]]固有のデフォルトアプリケーションを {{ic|''desktop''-mimeapps.list}} というファイルに定義することができます。{{ic|''desktop''}} ({{ic|XDG_CURRENT_DESKTOP}} 環境変数から) デスクトップ環境の名前です。例えば、/etc/xdg/xfce-mimeapps.list は、Xfce のシステム全体のデフォルトアプリケーションのオーバーライドを定義します。これらのデスクトップ固有のオーバーライドは、対応する非デスクトップ固有のファイルより優先されます。例えば、{{ic|/etc/xdg/xfce-mimeapps.list}} {{ic|/etc/xdg/mimeapps.list}} より優先されますが、 {{ic|~/.config/mimeapps.list}} によって上書きされます。
   
{{Tip|1=Although deprecated, several applications still read/write to {{ic|~/.local/share/applications/mimeapps.list}}. To simplify maintenance, simply symlink it to {{ic|~/.config/mimeapps.list}}: {{bc|$ ln -s ~/.config/mimeapps.list ~/.local/share/applications/mimeapps.list}}}}
+
{{Tip|非推奨ですが、{{ic|~/.local/share/applications/mimeapps.list}} を読み書きするアプリケーションはまだあります。メンテナンスを簡単にするために、{{ic|~/.config/mimeapps.list}} にシンボリックリンクしておくといいでしょう。}}
   
  +
{{Note|これらの場所には {{ic|defaults.list}} という名前のファイルがある場合もあります。このファイルは {{ic|mimeapps.list}} と似ていますが、デフォルトのアプリケーションのみをリストアップしています(追加/削除された関連付けはリストアップされません)。現在では非推奨となっており、手動で {{ic|mimeapps.list}} にマージする必要があります。}}
{{Note|You might also find files in these locations named {{ic|defaults.list}}. This file is similar to {{ic|mimeapps.list}} except it only lists default applications (not added/removed associations). It is now deprecated and should be manually merged with {{ic|mimeapps.list}}.}}
 
   
  +
スキャンされたすべてのファイルを検出するには、環境変数 ''XDG_UTILS_DEBUG_LEVEL=2'' を設定してデバッグ モードを有効にすることができます。例えば、{{ic|''xdg-mime query default <type>''}} コマンドは、MIME 情報を検索する各設定ファイルを表示します。
To discover all the files that are scanned it is possible to enable debug mode by setting the environment variable ''XDG_UTILS_DEBUG_LEVEL=2'': e.g. the {{ic|''xdg-mime query default <type>''}} command will print each configuration file it is searchin for mime information.
 
   
==== Format ====
+
==== 書式 ====
   
  +
以下の例を考えてみましょう:
Consider the following example:
 
   
 
{{hc|mimeapps.list|2=
 
{{hc|mimeapps.list|2=
87行目: 86行目:
 
image/jpeg=foo.desktop}}
 
image/jpeg=foo.desktop}}
   
  +
各セクションは、1 つ以上のデスクトップエントリを MIME タイプに割り当てます。
Each section assigns one or more desktop entries to MIME types.
 
* '''Added Associations''' indicates that the applications support opening that MIME type. For example, {{ic|bar.desktop}} and {{ic|baz.desktop}} can open JPEG images. This might affect the application list you see when right-clicking a file in a file browser.
 
* '''Removed Associations''' indicates that the applications ''do not'' support that MIME type. For example, {{ic|baz.desktop}} cannot open H.264 video.
 
* '''Default Applications''' indicates that the applications should be the default choice for opening that MIME type. For example, JPEG images should be opened with {{ic|foo.desktop}}. This implicitly adds an association between the application and the MIME type. If there are multiple applications, they are tried in order.
 
   
  +
* '''Added Associations''' はアプリケーションがその MIME タイプを開くことをサポートしていることを示します。たとえば、{{ic|bar.desktop}} と {{ic|baz.desktop}} は、JPEG 画像を開くことができます。これは、ファイルブラウザでファイルを右クリックしたときに表示されるアプリケーションのリストに影響する場合があります。
Each section is optional and can be omitted if unneeded.
 
  +
* '''Removed Associations''' はアプリケーションがその MIME タイプをサポートして''いない''ことを示します。たとえば、{{ic|baz.desktop}} は H.264 ビデオを開くことができません。
  +
* '''Default Applications''' はその MIME タイプを開くためのアプリケーションをデフォルトで選択する必要があることを示します。たとえば、JPEG 画像は {{ic|foo.desktop}} で開く必要があります。これは、アプリケーションと MIME タイプの間に暗黙のうちに関連付けを行います。複数のアプリケーションがある場合は、順番に試行されます。
   
  +
各セクションはオプションであり、不要な場合は省略可能です。
== Utilities ==
 
   
  +
== ユーティリティー ==
While it is possible to configure default applications and MIME types by directly editing [[#mimeapps.list|mimeapps.list]] and the [[#Shared MIME database|shared MIME database]], there are many tools that can simplify the process. These tools are also important because applications may delegate opening of files to these tools rather than trying to implement the MIME type standard themselves.
 
   
  +
[[#mimeapps.list|mimeapps.list]] と[[#共有 MIME データベース|共有 MIME データベース]]を直接編集することでデフォルトのアプリケーションと MIME タイプを設定することは可能ですが、このプロセスを簡略化する多くのツールがあります。これらのツールはまた、アプリケーションが自分自身で MIME タイプ標準を実装しようとするよりも、これらのツールにファイルのオープンを委ねるかもしれないので、重要である。
If you use a [[デスクトップ環境]] you should first check if it provides its own utility. That should be preferred over these alternatives.
 
   
  +
[[デスクトップ環境]]を使っているならば、まずその環境が独自のユーティリティを提供しているかどうかを確認すべきです。それは、これらの選択肢よりも優先されるべきものです。
The official [[xdg-utils]] contain tools for managing MIME types and default applications according to the XDG standard ([[xdg-utils#xdg-mime|xdg-mime]]). Most importantly it provides [[xdg-open]] which many applications use to open a file with its default application.
 
  +
  +
公式の [[xdg-utils]] には、XDG 標準に従って MIME タイプとデフォルトのアプリケーションを管理するためのツール ([[xdg-utils#xdg-mime|xdg-mime]]) が含まれています。最も重要なのは、多くのアプリケーションがデフォルトのアプリケーションでファイルを開くために使用する [[xdg-open]] が提供されていることです。
   
 
=== lsdesktopf ===
 
=== lsdesktopf ===
   
  +
{{AUR|lsdesktopf}} は、MIME データベースとデスクトップ MIME エントリを検索するいくつかの方法を提供します。
{{AUR|lsdesktopf}} provides several methods of searching the MIME database and desktop MIME entries.
 
   
For example, to see all MIME extensions in the system's ''.desktop'' files that have MIME type {{ic|video}} you can use {{ic|lsdesktopf --gm -gx video}} or to search in the XML database files use {{ic|lsdesktopf --gdx -gx video}}. To get a quick overview of how many and which ''.desktop'' files can be associated with a certain MIME type, use {{ic|lsdesktopf --gen-mimeapps}}. To see all file name extensions in XML database files, use {{ic|lsdesktopf --gdx -gfx}}.
+
例えば、システムの ''.desktop'' ファイルで MIME タイプが {{ic|video}} の全ての MIME 拡張を見るには {{ic|lsdesktopf --gm -gx video}} を、XML データベースファイルを検索するには {{ic|lsdesktopf --gdx -gx video}} を使ってください。特定の MIME タイプに関連する ''.desktop'' ファイルの数とその概要を知るには、{{ic|lsdesktopf --gen-mimeapps}} を使用します。XML データベースファイルのすべてのファイル名拡張子を見るには、{{ic|lsdesktopf --gdx -gfx}} を使用します。
   
 
=== selectdefaultapplication ===
 
=== selectdefaultapplication ===
   
  +
{{AUR|selectdefaultapplication-git}} は様々な mimetypes をサポートするアプリケーションをリストアップし、({{ic|mimeapps.list}} を修正することで) サポートする mimetypes の全てまたは一部をデフォルトとして素早く設定できる GUI アプリケーションです。
{{AUR|selectdefaultapplication-git}} is GUI application that lists up all applications supporting various mimetypes and lets you quickly set it as default for all or some of the mimetypes it supports (by modifying {{ic|mimeapps.list}}).
 
   
  +
「読みやすい」名前とファイル拡張子も表示されるので、mimetypes の名前を覚えておく必要はありません。
It shows the "readable" name and file extensions as well, so you do not need to remember the name of the mimetypes.
 
   
  +
== トラブルシューティング ==
== Troubleshooting ==
 
   
  +
ファイルが目的の既定のアプリケーションで開かれていない場合は、いくつかの原因が考えられます。ケースごとに確認する必要があるかもしれません。
If a file is not being opened by your desired default application, there are several possible causes. You may need to check each case.
 
   
  +
=== デスクトップエントリの欠落 ===
=== Missing desktop entry ===
 
   
  +
アプリケーションを MIME タイプに関連付けるには、[[デスクトップエントリ]]が必要です。そのようなエントリが存在し、アプリケーションでファイルを(手動で)開くことができることを確認してください。
A [[デスクトップエントリ]] is required in order to associate an application with a MIME type. Ensure that such an entry exists and can be used to (manually) open files in the application.
 
   
=== Missing association ===
+
=== 関連付けの欠落 ===
   
  +
アプリケーションのデスクトップエントリがその {{ic|MimeType}} キーの下で MIME タイプ を指定しない場合、そのタイプを開くためにアプリケーションが必要なときに考慮されません。[[#mimetype.list|mimeapps.list]] を編集して、.desktop ファイルと MIME タイプの間に関連付けを追加します。
If the application's desktop entry does not specify the MIME type under its {{ic|MimeType}} key, it will not be considered when an application is needed to open that type. Edit [[#mimeapps.list|mimeapps.list]] to add an association between the .desktop file and the MIME type.
 
   
  +
=== デフォルトでないアプリケーション ===
=== Non-default application ===
 
   
  +
デスクトップエントリが MIME タイプと関連付けられている場合、単にデフォルトとして設定されていないだけかもしれません。[[#mimeapps.list|mimeapps.list]] を編集してデフォルトの関連付けを設定してください。
If the desktop entry is associated with the MIME type, it may simply not be set as the default. Edit [[#mimeapps.list|mimeapps.list]] to set the default association.
 
   
=== Nonstandard association ===
+
=== 非標準の関連付け ===
   
  +
アプリケーションは、XDG 標準を無視したり、部分的にしか実装しなかったりすることができます。{{ic|~/.local/share/applications/mimeapps.list}} や {{ic|~/.local/share/applications/defaults.list}} などの非推奨のファイルが使用されていないかどうか確認してください。他のアプリケーション(Web ブラウザやファイル マネージャなど)からファイルを開こうとしている場合は、そのアプリケーションにデフォルトのアプリケーションを選択する独自の方法があるかどうかを確認します。
Applications are free to ignore or only partially implement the XDG standard. Check for usage of deprecated files such as {{ic|~/.local/share/applications/mimeapps.list}} and {{ic|~/.local/share/applications/defaults.list}}. If you are attempting to open the file from another application (e.g. a web browser or file manager) check if that application has its own method of selecting default applications.
 
   
  +
=== アプリケーションの起動に影響を与える .desktop ファイル内の変数 ===
=== Variables in .desktop files that affect application launch ===
 
   
Desktop environments and file managers supporting the specifications launch programs according to definition in the ''.desktop'' files. See [[デスクトップエントリ#アプリケーションエントリ]].
+
仕様をサポートするデスクトップ環境とファイルマネージャは、''.desktop'' ファイルの定義に従ってプログラムを起動します。[[デスクトップエントリ#アプリケーションエントリ]]を参照してください。
   
  +
通常、パッケージ化された ''.desktop'' ファイルの設定は必要ありませんが、バグがないとは限りません。関連付けに使用する ''.desktop'' ファイルの {{ic|MimeType}} 変数に必要な MIME タイプの記述があるアプリケーションでも、正しく起動しない、全く起動しない、ファイルを開かずに起動するなどの不具合が発生することがあります。
Usually, configuration of the packaged ''.desktop'' files is not required, but it may not be bug-free. Even if an application containing necessary MIME type description in the ''.desktop'' file {{ic|MimeType}} variable that is used for association, it can fail to start correctly, not start at all or start without opening a file.
 
   
This may happen, for example, if the {{ic|Exec}} variable is missing internal options needed for how to open a file, or how the application is shown in the menu. The {{ic|Exec}} variable usually begins with {{ic|%}}; for its currently supported options, see [https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables exec-variables].
+
これは、例えば、{{ic|Exec}} 変数に、ファイルを開く方法や、アプリケーションをメニューに表示する方法などに必要な内部オプションがない場合に起こるかもしれません。Exec 変数は通常 {{ic|%}} で始まります。現在サポートされているオプションについては、[https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables exec-variables] を参照してください。
   
  +
次の表は、MIME タイプが関連付けられている場合、アプリケーションの起動方法に影響を与える ''.desktop'' ファイルの主な変数エントリをリストアップしたものです。
The following table lists the main variable entries of ''.desktop'' files that affect how an application starts, if it has a MIME type associated with it.
 
   
 
{| class="wikitable"
 
{| class="wikitable"
! Variable names !! Example 1 content !! Example 2 content !! Description
+
! 変数名 !! 内容例1 !! 内容例2 !! 説明
 
|-
 
|-
| DBusActivatable || DBusActivatable=true || DBusActivatable=false || Application interact with [https://www.freedesktop.org/wiki/Software/dbus/ D-Bus]. <br> See also configuration: [https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#dbus D-Bus].
+
| DBusActivatable || DBusActivatable=true || DBusActivatable=false || アプリケーションは [https://www.freedesktop.org/wiki/Software/dbus/ D-Bus] とやり取りします。[https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#dbus D-Bus] 設定も参照してください。
 
|-
 
|-
| MimeType || MimeType=application/vnd.oasis.opendocument.text || MimeType=application/vnd.sun.xml.math || List of MIME types supported by application
+
| MimeType || MimeType=application/vnd.oasis.opendocument.text || MimeType=application/vnd.sun.xml.math || アプリケーションがサポートする MIME タイプのリスト
 
|-
 
|-
| StartupWMClass || StartupWMClass=google-chrome || StartupWMClass=xpad || Associate windows with the owning application
+
| StartupWMClass || StartupWMClass=google-chrome || StartupWMClass=xpad || ウィンドウを所有アプリケーションに関連付ける
 
|-
 
|-
| Terminal || Terminal=true || Terminal=false || Start in default terminal
+
| Terminal || Terminal=true || Terminal=false || デフォルトのターミナルで起動
 
|}
 
|}
  +
  +
{{TranslationStatus|XDG MIME Applications|2022-09-14|731706}}

2023年8月21日 (月) 19:03時点における最新版

関連記事

XDG MIME Applications specificationデフォルトアプリケーション を用意するために 共有 MIME データベースデスクトップエントリ から成り立っています。

  1. XDG MIME Applications は どの MIME type を扱うことができるかを デスクトップエントリ を使って定義します。
  2. desktop-file-utilspacman フック であり、デスクトップエントリが扱う MIME type のデータベースを構築します。詳細は update-desktop-database(1) を見て下さい。
  3. XDG MIME Applications は /usr/share/mime/packages/ に XML ファイルを置くことにより新しい MIME タイプ をインストールできます。
  4. shared-mime-info は Shared MIME-Info database cache を構築するために pacman フック を登録します。詳しくは update-mime-database(1) を参照して下さい。
  5. デスクトップ環境 とユーザーは mimeapps.list ファイルを通じて特定の MIME タイプ に紐付くデフォルトアプリケーションの変更や設定、削除ができます。

共有 MIME データベース

XDG Shared MIME-info Database specification 仕様は、デスクトップ環境間での MIME データベースの共有を容易にし、アプリケーションがシステム全体で新しい MIME タイプを簡単に登録できるようにするものです。

データベースは、/usr/share/mime/packages/ にあるパッケージによってインストールされた XML ファイルから shared-mime-info のツールを使って構築されます。

/usr/share/mime/ にあるファイルを直接編集してはいけませんが、 ~/.local/share/mime/ ツリーにあるデータベースをユーザーごとに管理することは可能です。

「URI スキームの処理 [...] は、x-scheme-handler/foo MIME タイプを処理するアプリケーションを通して処理されます(foo は問題の URI スキーム)」[1]

新しい MIME タイプ

この例では、新しい MIME タイプ application/x-foobar を定義し、.foo で終わる名前を持つすべてのファイルに割り当てています。単に次のようなファイルを作成します。

~/.local/share/mime/packages/application-x-foobar.xml
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <mime-type type="application/x-foobar">
        <comment>foo file</comment>
        <icon name="application-x-foobar"/>
        <glob-deleteall/>
        <glob pattern="*.foo"/>
    </mime-type>
</mime-info>

次に、MIME データベースを更新します。

$ update-mime-database ~/.local/share/mime

もちろん、デスクトップエントリが MIME タイプに関連付けられていない場合、これは効果がありません。新しいデスクトップエントリを作成するか、mimeapps.list を変更する必要がある場合があります。

mimeapps.list

XDG 標準は、デスクトップ環境を設定するための最も一般的な規格です。各 MIME タイプのデフォルトのアプリケーションは、mimeapps.list ファイルに格納されています。これらは以下の順序で検索され、先に関連づけられたものが後に関連づけられたものよりも優先されます。

Path Usage
~/.config/mimeapps.list ユーザーオーバーライド
/etc/xdg/mimeapps.list システム全体のオーバーライド
~/.local/share/applications/mimeapps.list (非推奨) ユーザーオーバーライド
/usr/local/share/applications/mimeapps.list
/usr/share/applications/mimeapps.list
ディストリビューション提供のデフォルト

さらに、デスクトップ環境固有のデフォルトアプリケーションを desktop-mimeapps.list というファイルに定義することができます。desktop は (XDG_CURRENT_DESKTOP 環境変数から) デスクトップ環境の名前です。例えば、/etc/xdg/xfce-mimeapps.list は、Xfce のシステム全体のデフォルトアプリケーションのオーバーライドを定義します。これらのデスクトップ固有のオーバーライドは、対応する非デスクトップ固有のファイルより優先されます。例えば、/etc/xdg/xfce-mimeapps.list/etc/xdg/mimeapps.list より優先されますが、 ~/.config/mimeapps.list によって上書きされます。

ヒント: 非推奨ですが、~/.local/share/applications/mimeapps.list を読み書きするアプリケーションはまだあります。メンテナンスを簡単にするために、~/.config/mimeapps.list にシンボリックリンクしておくといいでしょう。
ノート: これらの場所には defaults.list という名前のファイルがある場合もあります。このファイルは mimeapps.list と似ていますが、デフォルトのアプリケーションのみをリストアップしています(追加/削除された関連付けはリストアップされません)。現在では非推奨となっており、手動で mimeapps.list にマージする必要があります。

スキャンされたすべてのファイルを検出するには、環境変数 XDG_UTILS_DEBUG_LEVEL=2 を設定してデバッグ モードを有効にすることができます。例えば、xdg-mime query default <type> コマンドは、MIME 情報を検索する各設定ファイルを表示します。

書式

以下の例を考えてみましょう:

mimeapps.list
[Added Associations]
image/jpeg=bar.desktop;baz.desktop
video/H264=bar.desktop
[Removed Associations]
video/H264=baz.desktop
[Default Applications]
image/jpeg=foo.desktop

各セクションは、1 つ以上のデスクトップエントリを MIME タイプに割り当てます。

  • Added Associations はアプリケーションがその MIME タイプを開くことをサポートしていることを示します。たとえば、bar.desktopbaz.desktop は、JPEG 画像を開くことができます。これは、ファイルブラウザでファイルを右クリックしたときに表示されるアプリケーションのリストに影響する場合があります。
  • Removed Associations はアプリケーションがその MIME タイプをサポートしていないことを示します。たとえば、baz.desktop は H.264 ビデオを開くことができません。
  • Default Applications はその MIME タイプを開くためのアプリケーションをデフォルトで選択する必要があることを示します。たとえば、JPEG 画像は foo.desktop で開く必要があります。これは、アプリケーションと MIME タイプの間に暗黙のうちに関連付けを行います。複数のアプリケーションがある場合は、順番に試行されます。

各セクションはオプションであり、不要な場合は省略可能です。

ユーティリティー

mimeapps.list共有 MIME データベースを直接編集することでデフォルトのアプリケーションと MIME タイプを設定することは可能ですが、このプロセスを簡略化する多くのツールがあります。これらのツールはまた、アプリケーションが自分自身で MIME タイプ標準を実装しようとするよりも、これらのツールにファイルのオープンを委ねるかもしれないので、重要である。

デスクトップ環境を使っているならば、まずその環境が独自のユーティリティを提供しているかどうかを確認すべきです。それは、これらの選択肢よりも優先されるべきものです。

公式の xdg-utils には、XDG 標準に従って MIME タイプとデフォルトのアプリケーションを管理するためのツール (xdg-mime) が含まれています。最も重要なのは、多くのアプリケーションがデフォルトのアプリケーションでファイルを開くために使用する xdg-open が提供されていることです。

lsdesktopf

lsdesktopfAUR は、MIME データベースとデスクトップ MIME エントリを検索するいくつかの方法を提供します。

例えば、システムの .desktop ファイルで MIME タイプが video の全ての MIME 拡張を見るには lsdesktopf --gm -gx video を、XML データベースファイルを検索するには lsdesktopf --gdx -gx video を使ってください。特定の MIME タイプに関連する .desktop ファイルの数とその概要を知るには、lsdesktopf --gen-mimeapps を使用します。XML データベースファイルのすべてのファイル名拡張子を見るには、lsdesktopf --gdx -gfx を使用します。

selectdefaultapplication

selectdefaultapplication-gitAUR は様々な mimetypes をサポートするアプリケーションをリストアップし、(mimeapps.list を修正することで) サポートする mimetypes の全てまたは一部をデフォルトとして素早く設定できる GUI アプリケーションです。

「読みやすい」名前とファイル拡張子も表示されるので、mimetypes の名前を覚えておく必要はありません。

トラブルシューティング

ファイルが目的の既定のアプリケーションで開かれていない場合は、いくつかの原因が考えられます。ケースごとに確認する必要があるかもしれません。

デスクトップエントリの欠落

アプリケーションを MIME タイプに関連付けるには、デスクトップエントリが必要です。そのようなエントリが存在し、アプリケーションでファイルを(手動で)開くことができることを確認してください。

関連付けの欠落

アプリケーションのデスクトップエントリがその MimeType キーの下で MIME タイプ を指定しない場合、そのタイプを開くためにアプリケーションが必要なときに考慮されません。mimeapps.list を編集して、.desktop ファイルと MIME タイプの間に関連付けを追加します。

デフォルトでないアプリケーション

デスクトップエントリが MIME タイプと関連付けられている場合、単にデフォルトとして設定されていないだけかもしれません。mimeapps.list を編集してデフォルトの関連付けを設定してください。

非標準の関連付け

アプリケーションは、XDG 標準を無視したり、部分的にしか実装しなかったりすることができます。~/.local/share/applications/mimeapps.list~/.local/share/applications/defaults.list などの非推奨のファイルが使用されていないかどうか確認してください。他のアプリケーション(Web ブラウザやファイル マネージャなど)からファイルを開こうとしている場合は、そのアプリケーションにデフォルトのアプリケーションを選択する独自の方法があるかどうかを確認します。

アプリケーションの起動に影響を与える .desktop ファイル内の変数

仕様をサポートするデスクトップ環境とファイルマネージャは、.desktop ファイルの定義に従ってプログラムを起動します。デスクトップエントリ#アプリケーションエントリを参照してください。

通常、パッケージ化された .desktop ファイルの設定は必要ありませんが、バグがないとは限りません。関連付けに使用する .desktop ファイルの MimeType 変数に必要な MIME タイプの記述があるアプリケーションでも、正しく起動しない、全く起動しない、ファイルを開かずに起動するなどの不具合が発生することがあります。

これは、例えば、Exec 変数に、ファイルを開く方法や、アプリケーションをメニューに表示する方法などに必要な内部オプションがない場合に起こるかもしれません。Exec 変数は通常 % で始まります。現在サポートされているオプションについては、exec-variables を参照してください。

次の表は、MIME タイプが関連付けられている場合、アプリケーションの起動方法に影響を与える .desktop ファイルの主な変数エントリをリストアップしたものです。

変数名 内容例1 内容例2 説明
DBusActivatable DBusActivatable=true DBusActivatable=false アプリケーションは D-Bus とやり取りします。D-Bus 設定も参照してください。
MimeType MimeType=application/vnd.oasis.opendocument.text MimeType=application/vnd.sun.xml.math アプリケーションがサポートする MIME タイプのリスト
StartupWMClass StartupWMClass=google-chrome StartupWMClass=xpad ウィンドウを所有アプリケーションに関連付ける
Terminal Terminal=true Terminal=false デフォルトのターミナルで起動
翻訳ステータス: このページは en:XDG MIME Applications の翻訳バージョンです。最後の翻訳日は 2022-09-14 です。もし英語版に 変更 があれば、翻訳の同期を手伝うことができます。