「XDG MIME Applications」の版間の差分

提供: ArchWiki
ナビゲーションに移動 検索に移動
(→‎Format: 飜訳)
(→‎Utilities: 一部飜訳)
95行目: 95行目:
 
各セクションはオプションであり、不要な場合は省略可能です。
 
各セクションはオプションであり、不要な場合は省略可能です。
   
== Utilities ==
+
== ユーティリチュ ==
   
  +
[[#mimeapps.list|mimeapps.list]] と[[共有 MIME データベース#|共有 MIME データベース]]を直接編集することでデフォルトのアプリケーションと MIME タイプを設定することは可能ですが、このプロセスを簡略化する多くのツールがあります。これらのツールはまた、アプリケーションが自分自身で MIME タイプ標準を実装しようとするよりも、これらのツールにファイルのオープンを委ねるかもしれないので、重要である。
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.
 
   
  +
もしあなたが[[デスクトップ環境]]を使っているならば、まずその環境が独自のユーティリティを提供しているかどうかを確認すべきです。それは、これらの選択肢よりも優先されるべきものです。
If you use a [[デスクトップ環境]] you should first check if it provides its own utility. That should be preferred over these alternatives.
 
   
  +
公式の [[xdg-utils]] には、XDG 標準に従って MIME タイプとデフォルトのアプリケーションを管理するためのツール ([[xdg-utils#xdg-mime|xdg-mime]]) が含まれています。最も重要なのは、多くのアプリケーションがデフォルトのアプリケーションでファイルを開くために使用する [[xdg-open]] が提供されていることです。
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.
 
   
 
=== lsdesktopf ===
 
=== lsdesktopf ===

2022年9月7日 (水) 10:41時点における版

関連記事

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

  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 type をインストールできます。
  4. shared-mime-info は Shared MIME-Info database cache を構築するために pacman フック を登録します。詳しくは update-mime-database(1) を参照して下さい。
  5. デスクトップ環境 とユーザーは mimeapps.list ファイルを通じて特定の MIME type に紐付くデフォルトアプリケーションの変更や設定、削除ができます。

共有 MIME データベース

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

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

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

"URI scheme handling [..] are handled through applications handling the x-scheme-handler/foo MIME type, where foo is the URI scheme in question."[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 (非推奨) user overrides
/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 によって上書きされます。

ヒント: Although deprecated, several applications still read/write to ~/.local/share/applications/mimeapps.list. To simplify maintenance, simply symlink it to ~/.config/mimeapps.list:
$ ln -s ~/.config/mimeapps.list ~/.local/share/applications/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 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 video you can use lsdesktopf --gm -gx video or to search in the XML database files use 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 lsdesktopf --gen-mimeapps. To see all file name extensions in XML database files, use lsdesktopf --gdx -gfx.

selectdefaultapplication

selectdefaultapplication-gitAUR 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 mimeapps.list).

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

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

If the application's desktop entry does not specify the MIME type under its MimeType key, it will not be considered when an application is needed to open that type. Edit mimeapps.list to add an association between the .desktop file and the MIME type.

Non-default application

If the desktop entry is associated with the MIME type, it may simply not be set as the default. Edit mimeapps.list to set the default association.

Nonstandard association

Applications are free to ignore or only partially implement the XDG standard. Check for usage of deprecated files such as ~/.local/share/applications/mimeapps.list and ~/.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.

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 デスクトップエントリ#アプリケーションエントリ.

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 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 Exec variable is missing internal options needed for how to open a file, or how the application is shown in the menu. The Exec variable usually begins with %; for its currently supported options, see exec-variables.

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.

Variable names Example 1 content Example 2 content Description
DBusActivatable DBusActivatable=true DBusActivatable=false Application interact with D-Bus.
See also configuration: D-Bus.
MimeType MimeType=application/vnd.oasis.opendocument.text MimeType=application/vnd.sun.xml.math List of MIME types supported by application
StartupWMClass StartupWMClass=google-chrome StartupWMClass=xpad Associate windows with the owning application
Terminal Terminal=true Terminal=false Start in default terminal