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

提供: ArchWiki
2015年10月10日 (土) 10:38時点における162.158.6.69 (トーク)による版 (→‎ファイルマネージャ)
ナビゲーションに移動 検索に移動

関連記事

特定のファイルタイプで使用するようにデフォルトアプリケーションを設定することが可能です (例: HTML ファイルを表示するプログラムとして Firefox ウェブブラウザを設定)。ちゃんと設定することで、使用したいアプリケーションでファイルを素早く簡単に開いたり編集することができます。Linux でデフォルトアプリケーションを設定する方法は様々です。このページでは最も一般的な方法を説明します: ファイルマネージャ, MIME タイプ, 環境変数。

MIME タイプとデスクトップエントリ

最近ではアプリケーションはデスクトップエントリを使って起動されます。この方法では、アプリケーションが開くことができるファイルの種類 (正確に言えば MIME タイプ) を定義できます。例えば gimp.desktop には MimeType=image/bmp;image/gif;... と記述されています。

freedesktop.orgAssociation between MIME types and applications の標準に従って特定の MIME タイプのデフォルトの (使いたい) アプリケーションを指定することを推奨しています。設定するには以下のパスにある mimeapps.list という名前のファイルを探して書き込みを行う必要があります:

パス 使用方法
$HOME/.config/$desktop-mimeapps.list デスクトップごとに、ユーザーが定義します
$HOME/.config/mimeapps.list ユーザーが定義します
/etc/xdg/$desktop-mimeapps.list デスクトップごとに、システム管理者やソフトウェアが定義します
/etc/xdg/mimeapps.list システム管理者やソフトウェアが定義します
$HOME/.local/share/applications/$desktop-mimeapps.list デスクトップごとに、互換性のために存在しますが現在は非推奨です
$HOME/.local/share/applications/mimeapps.list 互換性のために存在しますが現在は非推奨です
/usr/local/share/applications/$desktop-mimeapps.list
/usr/share/applications/$desktop-mimeapps.list
ディストリビューションによるデフォルト、デスクトップごと
/usr/local/share/applications/mimeapps.list
/usr/share/applications/mimeapps.list
ディストリビューションによるデフォルト

上の表にある、$VARS は環境変数で $desktop は使用しているデスクトップの名前です (小文字)。例: kde, gnome, xfce, etc。

特定の MIME タイプのデフォルトアプリケーションを指定するには mimeapps.list ファイルの [Default Applications] グループに記述します。以下の例では、mimetype1 ではアプリケーション default1.desktop または (default1 がインストールされていない場合) default2.desktop が使われます:

[Default Applications]
mimetype1=default1.desktop;default2.desktop

アプリケーションはセミコロンで区切って デスクトップファイル ID を使って指定します。

In the absence of such an entry, the next mimeapps.list in the path hierarchy will be checked. Once all levels have been checked, if no entry could be found, then programs can pick any of the .desktop files associated with the MIME-type, taking into account added and removed associations as per these other groups which may be specified in mimeapps.list files:

[Added Associations]
mimetype1=foo1.desktop;foo2.desktop;foo3.desktop
mimetype2=foo4.desktop
[Removed Associations]
mimetype1=foo5.desktop

The [Added Associations] group defines additional associations of applications with MIME-types, as if the .desktop file was listing this MIME-type in the first place. The [Removed Associations] group removes associations of applications with MIME-types, as if the .desktop file was not listing this MIME-type in the first place. The entries in [Default Applications] should also be considered to add an association between application and MIME-type in the same manner.

ノート:
  • Arch Linux itself does not provide any system-wide preferences for associations, but other distributions and specific desktop environments may do so via mimeapps.list or the older but deprecated defaults.list files.
  • デフォルトアプリケーションの設定に関する仕様は最近変更されたばかりであり、全てのプログラムが仕様に準拠しているわけではありません。事実、freedesktop.org の xdg-utils パッケージに含まれているプログラムでさえ彼らが決めた仕様に完全には従っていないものがあります。
  • Your choice of desktop environment, or none, will also affect how your default applications are stored.
  • When the program update-desktop-database is run (usually as root during the (un)installation of a package), it updates files called mimeinfo.cache in the /usr/local/share/applications and /usr/share/applications directories. These files keep track of which MIME-types are associated with which .desktop files overall. This file should not be edited by the user.

ファイルマネージャ

ほとんどのファイルマネージャは,様々なファイルタイプに対して特定のアプリケーションをデフォルトのアプリケーションとして設定することができます。いつでも新たなデフォルトアプリケーションを設定することができます。例えば、Xfce の標準ファイルマネージャである thunar を使ってデフォルトアプリケーションを設定するには:

  • 設定したいファイルタイプを持つファイルを 右クリック する
  • Open with another application を選ぶ
  • 所望のアプリケーションを選ぶ
  • Use as default for this kind of file チェックボックスにチェックが入っているか確認する
  • Open ボタンをクリックする


PCManFMspacefm のような、他のほとんどのファイルマネージャでも一般的な手順は非常に似ています。

Gnome Control Center

If it's installed, run gnome-control-center, open System > Details > Default Applications.

gnome-defaults-list

gnome-defaults-listAUR is available from the AUR, and contains a list of file-types and programs specific to the GNOME desktop. The list is installed to /etc/gnome/defaults.list.

Open this file with a text editor. Here you can replace a given application with the name of the program of your choice. For example, the media-player totem can be replaced with another, such as vlc. Save the file to ~/.local/share/applications/defaults.list.

xdg-open

xdg-open is a desktop-independent tool for starting default applications. Many applications invoke the xdg-open command internally. xdg-open uses xdg-mime to query ~/.local/share/applications/mimeapps.list (among other things; if you use a mainstream DE like GNOME, KDE or LXDE, xdg-open might try using their specific tools before xdg-mime) to find the MIME type of the file that is to be opened and the default application associated with that MIME type.

See xdg-open for more information.

ファイルの関連付けのカスタマイズ

The following method creates a custom mime type and file association manually. This is useful if your desktop does not have a mime type/file association editor installed. In this example, a fictional multimedia application 'foobar' will be associated with all *.foo files. This will only affect the current user.

First, create the file ~/.local/share/mime/packages/application-x-foobar.xml:

$ mkdir -p ~/.local/share/mime/packages
$ cd ~/.local/share/mime/packages
$ touch application-x-foobar.xml

Then edit ~/.local/share/mime/packages/application-x-foobar.xml and add this text:

<?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>

Note that you can use any icon, including one for another application.

Next, edit or create the file ~/.local/share/applications/foobar.desktop to contain something like:

[Desktop Entry]
Name=Foobar
Exec=/usr/bin/foobar
MimeType=application/x-foobar
Icon=foobar
Terminal=false
Type=Application
Categories=AudioVideo;Player;Video;
Comment=

Note that Categories should be set appropriately for the application type (in this example, a multimedia app).

Now update the applications and mime database with:

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

Programs that use mime types, such as file managers, should now open *.foo files with foobar. (You may need to restart your file manager to see the change.)

複数のデスクトップ環境の設定を管理

.desktop ファイルの OnlyShowIn フィールドを利用することができます。このページ を見て下さい。

環境変数を使う

グラフィカルでないプログラムのほとんどは EDITORBROWSER などの環境変数を使います。環境変数はターミナルの自動起動ファイルで設定できます (例: ~/.bashrc):

~/.bashrc
export EDITOR="nano"
export BROWSER="firefox"

トラブルシューティング

(ファイルマネージャにある) コンテキストメニューの「他のアプリケーションで開く」でアプリケーションが表示されない

ときどき、右クリックの他のアプリケーションで開くダイアログに特定のアプリケーションが表示されないことがあります。この問題を修正するには、/usr/share/applications にある .desktop ファイルを探して、root で編集し、Exec= 行の末尾に %U を追加してください。例えば Kile の場合、/usr/share/applications/kde4/kile.desktop を編集して Exec=kile という行を Exec=kile %U と変更する必要があります。この問題に気づいたときは、上流のプロジェクトにバグの報告をするようにしてください。

You may also have to edit the MimeType list in the .desktop file if you install extensions that allow an application to handle additional MIME types.