「デフォルトアプリケーション」の版間の差分
(→リソースオープナー: 翻訳) |
(→ミニマルなリプレイスメント: 同期) |
||
(3人の利用者による、間の7版が非表示) | |||
8行目: | 8行目: | ||
! メソッド !! XDG を使用 !! アプリケーション例 |
! メソッド !! XDG を使用 !! アプリケーション例 |
||
|- |
|- |
||
− | | [https://developer.gnome.org/gio/stable/GAppInfo.html GIO |
+ | | [https://developer.gnome.org/gio/stable/GAppInfo.html GIO の GAppInfo] || Yes || [[Firefox]], [[GNOME Files]], [[PCManFM]], [[Thunar]], [[Thunderbird]], [[Telegram]] |
|- |
|- |
||
| {{ic|/usr/bin/xdg-open}} || By default || [[Chromium]] (ダウンロードしたファイルを開く) |
| {{ic|/usr/bin/xdg-open}} || By default || [[Chromium]] (ダウンロードしたファイルを開く) |
||
113行目: | 113行目: | ||
=== whippet === |
=== whippet === |
||
− | {{aur|whippet}} |
+ | {{aur|whippet}} は {{ic|xdg-open}} に似たツール {{ic|whippet}} を提供します。 {{pkg|libnotify}} でエラーを表示し、{{pkg|dmenu}} で開くアプリケーションの選択肢を表示することで、X11 との統合を実現しています。 |
# open a file with its default application |
# open a file with its default application |
||
121行目: | 121行目: | ||
$ whippet -m photo.jpeg |
$ whippet -m photo.jpeg |
||
+ | [[XDG MIME Applications]] の実装に加えて、''whippet'' は application/MIME タイプ/正規表現の関連性を加えた SQlite データベースを使って、どのアプリケーションを使用するかを決定することができます。 |
||
− | 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 === |
||
− | {{ |
+ | Rust で書かれた {{Pkg|handlr}} は {{ic|xdg-open}} と {{ic|xdg-mime}} の機能を効率的なインタフェースで提供します。 |
+ | {{ic|xdg-utils}} と比較すると、以下のような点が挙げられます。 |
||
− | Compared to {{ic|xdg-utils}}, it includes: |
||
+ | * 拡張子による関連付けの設定、mime タイプを調べたり覚えたりする必要性を排除 |
||
− | * setting associations by extension, removing the need to look up or remember mime types |
||
+ | * mime タイプと拡張子の検証 |
||
− | * validation for mime types and extensions |
||
− | * |
+ | * {{ic|mimeapps.list}} から無効なエントリを削除します。 |
+ | * ファイル名が曖昧な場合、ファイルの内容から mime タイプをインテリジェントに検出します。 |
||
− | * intelligent detection of mime types from file content in case filename is ambiguous |
||
+ | * mime、拡張子、デスクトップエントリーのオートコンプリートに対応 |
||
− | * autocompletion of mimes, extensions, and desktop entries |
||
# The following two are identical |
# The following two are identical |
||
149行目: | 149行目: | ||
handlr launch x-scheme-handler/https -- https://google.ca |
handlr launch x-scheme-handler/https -- https://google.ca |
||
− | {{aur|xdg-utils-handlr}} |
+ | {{aur|xdg-utils-handlr}} は、内部で {{ic|handlr}} を使用して {{ic|xdg-utils}} を置き換える{{ic|xdg-open}} を提供します。 |
+ | === ミニマルなリプレイスメント === |
||
− | === Minimalist replacements === |
||
+ | 以下のパッケージは独自の {{ic|/usr/bin/xdg-open}} スクリプトを提供しているため、 {{Pkg|xdg-utils}} と競合して提供されます。 |
||
− | The following packages conflict with and provide {{Pkg|xdg-utils}} because they provide their own {{ic|/usr/bin/xdg-open}} script. |
||
+ | もし、{{Pkg|xdg-utils}} を使用しながら、これらのリソースオープナーを使用したい場合、{{ic|/usr/bin}} より前の PATH ディレクトリに手動でインストールしてください。 |
||
− | If you want to use one of these resource openers while still being able to use {{Pkg|xdg-utils}}, install them manually in a PATH directory before {{ic|/usr/bin}}. |
||
+ | * {{AUR|mimi-git}} - 130 行の Bash スクリプトで、MIME タイプごとにコマンド引数を変更することができます。 |
||
− | * {{AUR|linopen}} - 170-line Bash script, supports regex rules |
||
+ | * {{AUR|busking-git}} - 80 行の Perl スクリプトで、''mimi''に似ていますが、正規表現もサポートしています。 |
||
− | * {{AUR|mimi-git}} - 130-line Bash script, can change command arguments for each MIME type |
||
− | * {{AUR|busking-git}} - 80-line Perl script similar to ''mimi'' but also supports regex rules |
||
− | * {{AUR|sx-open}} - 60-line Bash script, uses a simple shell-based config file |
||
− | ==== |
+ | ==== mailcap の実行 ==== |
− | {{Warning| |
+ | {{Warning|{{AUR|run-mailcap}} を使うと {{ic|xdg-open}} がそれに委譲する可能性があります。もし {{Pkg|mailcap}} の {{ic|/etc/mailcap}} を使っているならば、これも {{ic|xdg-open}} に委譲されるので、無限ループを引き起こします。}} |
2024年1月18日 (木) 16:34時点における最新版
プログラムはさまざまな方法でデフォルトのアプリケーションの関連付けを実装します。コマンドラインプログラムは伝統的に環境変数を使いますが、グラフィカルアプリケーションでは、GIO API、Qt API または xdg-utils の一部である /usr/bin/xdg-open
を実行することで、XDG MIME Applications を使用する傾向があります。xdg-open や XDG MIME Applications は非常に複雑なので、様々な代替リソースオープナーが開発されました。次の表は、それぞれの方法のアプリケーション例です。
メソッド | XDG を使用 | アプリケーション例 |
---|---|---|
GIO の 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 を提供します。
目次
背景情報
プログラムは、ファイルや URI をユーザーの好みのアプリケーションで開く必要がある場合があります。ユーザーの好みのアプリケーションでファイルを開くには、ファイルタイプを検出し(通常はファイル名の拡張子か MIME タイプにマッピングされたマジックナンバーを使用)、そのファイルタイプに関連するアプリケーションが存在する必要があります。
Heirloom UNIX のプログラムでは、MIME タイプの検出には mime.types を、アプリケーションの関連付けには mailcap を使用していました。
リソースオープナー
- XDG MIME Apps: XDG MIME Applications 仕様を実装しています。
- RegEx ルール: 正規表現を使用して MIME タイプとアプリケーションを関連付けることができます。
- URI サポート: 任意の URI スキームをアプリケーションと関連付けることができます。
名前 | パッケージ | XDG MIME Apps | RegEx ルール | URI サポート |
---|---|---|---|---|
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 (xdg-utils の一部) は、XDG MIME Applications を実装し、多くのプログラムで使用されています。
xdg-utils 版の xdg-open は複雑なため、間違ったデフォルトのアプリケーションが開かれる場合はデバッグが困難になる場合があります。このため、これを改善しようとする代替手段が多く存在します。これらの代替品のいくつかは、/usr/bin/xdg-open
実行ファイルを置き換えるので、ほとんどのアプリケーションのデフォルトのアプリケーションの動作を変更します。その他は、単にデフォルトアプリケーションを選択するための代替方法を提供するものです。
perl-file-mimeinfo
perl-file-mimeinfo は mimeopen(1p) と mimetype(1p) というツールを提供します。これらは、xdg-utils の同等品より少し良いインターフェイスを持っています。
# 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
最も重要なことは、xdg-utils プログラムがデスクトップ環境を検出しない場合、MIME タイプ検出のために mimetype
の代わりに file
を実際に呼び出すことです。file
は XDG 標準に準拠していないため、これは重要なことです。
mimeo
mimeoAUR は xdg-open
と xdg-mime
の機能を統合したツール mimeo
を提供します。
# 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
しかし、xdg-utils との大きな違いは、mimeoはより複雑な関連付けを可能にするカスタムの「関連付けファイル」をサポートしていることです。例えば、正規表現のマッチに基づいた特定のコマンドライン引数を渡すことができます。
# 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 は、デスクトップ環境が検出されない場合に xdg-open
が mimeo にフォールバックするように xdg-utils にパッチを当てます。
whippet
whippetAUR は xdg-open
に似たツール whippet
を提供します。 libnotify でエラーを表示し、dmenu で開くアプリケーションの選択肢を表示することで、X11 との統合を実現しています。
# 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
XDG MIME Applications の実装に加えて、whippet は application/MIME タイプ/正規表現の関連性を加えた SQlite データベースを使って、どのアプリケーションを使用するかを決定することができます。
handlr
Rust で書かれた handlr は xdg-open
と xdg-mime
の機能を効率的なインタフェースで提供します。
xdg-utils
と比較すると、以下のような点が挙げられます。
- 拡張子による関連付けの設定、mime タイプを調べたり覚えたりする必要性を排除
- mime タイプと拡張子の検証
mimeapps.list
から無効なエントリを削除します。- ファイル名が曖昧な場合、ファイルの内容から mime タイプをインテリジェントに検出します。
- mime、拡張子、デスクトップエントリーのオートコンプリートに対応
# 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 は、内部で handlr
を使用して xdg-utils
を置き換えるxdg-open
を提供します。
ミニマルなリプレイスメント
以下のパッケージは独自の /usr/bin/xdg-open
スクリプトを提供しているため、 xdg-utils と競合して提供されます。
もし、xdg-utils を使用しながら、これらのリソースオープナーを使用したい場合、/usr/bin
より前の PATH ディレクトリに手動でインストールしてください。
- mimi-gitAUR - 130 行の Bash スクリプトで、MIME タイプごとにコマンド引数を変更することができます。
- busking-gitAUR - 80 行の Perl スクリプトで、mimiに似ていますが、正規表現もサポートしています。