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

提供: ArchWiki
ナビゲーションに移動 検索に移動
(カテゴリーを修正)
(4人の利用者による、間の13版が非表示)
1行目: 1行目:
[[Category:クトップ環境]]
+
[[Category:テム管理]]
 
[[en:Default applications]]
 
[[en:Default applications]]
[[zh-cn:Default Applications]]
+
[[ru:Default applications]]
  +
[[zh-hans:Default applications]]
{{Related articles start}}
 
  +
プログラムはさまざまな方法でデフォルトのアプリケーションの関連付けを実装します。コマンドラインプログラムは伝統的に[[環境変数#デフォルトプログラム|環境変数]]を使いますが、グラフィカルアプリケーションでは、[[Wikipedia:GIO (software)|GIO]] API、[[Qt]] API または [[xdg-utils]] の一部である {{ic|/usr/bin/xdg-open}} を実行することで、[[XDG MIME Applications]] を使用する傾向があります。[[xdg-open]] や [[XDG MIME Applications]] は非常に複雑なので、様々な代替リソースオープナーが開発されました。次の表は、それぞれの方法のアプリケーション例です。
{{Related|デスクトップ環境}}
 
{{Related|ウィンドウマネージャ}}
 
{{Related articles end}}
 
特定のファイルタイプで使用するようにデフォルトアプリケーションを設定することが可能です (例: {{ic|HTML}} ファイルを表示するプログラムとして [[Firefox]] ウェブブラウザを設定)。ちゃんと設定することで、使用したいアプリケーションでファイルを素早く簡単に開いたり編集することができます。Linux でデフォルトアプリケーションを設定する方法は様々です。このページでは最も一般的な方法を説明します: ファイルマネージャ, MIME タイプ, 環境変数。
 
   
  +
{| class=wikitable
== MIME タイプとデスクトップエントリ ==
 
  +
! メソッド !! XDG を使用 !! アプリケーション例
  +
|-
  +
| [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]] (ダウンロードしたファイルを開く)
  +
|-
  +
| custom || Usually not || [[mc]], [[ranger]]
  +
|-
  +
| [[環境変数#デフォルトプログラム|環境変数]] || No || [[man]], [[sudoedit]], [[systemctl]]
  +
|-
  +
| [[D-Bus]] の FileManager1 || org.freedesktop.FileManager1 || [[Firefox]] (Open containing folder), Zotero (ファイルを表示), [[Telegram]] (フォルダに表示)
  +
|}
   
  +
多くの[[デスクトップ環境]]とグラフィカル[[ファイルマネージャ]]は、デフォルトのアプリケーションを設定するための GUI を提供します。
最近ではアプリケーションは[[デスクトップエントリ]]を使って起動されます。この方法では、アプリケーションが開くことができるファイルの種類 (正確に言えば MIME タイプ) を定義できます。例えば {{ic|gimp.desktop}} には {{ic|<nowiki>MimeType=image/bmp;image/gif;...</nowiki>}} と記述されています。
 
   
  +
== Background information ==
[http://www.freedesktop.org/wiki freedesktop.org] は [http://standards.freedesktop.org/mime-apps-spec/mime-apps-spec-1.0.html Association between MIME types and applications] の標準に従って特定の MIME タイプのデフォルトの (使いたい) アプリケーションを指定することを推奨しています。設定するには以下のパスにある {{ic|mimeapps.list}} という名前のファイルを探して書き込みを行う必要があります:
 
  +
  +
Programs sometimes need to open a file or a [[Wikipedia:Uniform Resource Identifier|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 [[Wikipedia:List of file signatures|magic numbers]] mapped to [[Wikipedia:Media type|MIME types]]) and there needs to be an application associated with the filetype.
  +
  +
[[Heirloom]] UNIX programs used [[Wikipedia:Media type#mime.types|mime.types]] for MIME type detection and [[Wikipedia:Media type#Mailcap|mailcap]] for application association.
  +
  +
== リソースオープナー ==
  +
  +
* '''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
   
 
{| class="wikitable"
 
{| class="wikitable"
  +
! Name !! Package !! XDG MIME Apps !! RegEx rules !! URI support
! パス !! 使用方法
 
 
|-
 
|-
  +
|[[xdg-open]] || [[xdg-utils]] || {{Yes}} || {{No}} || {{Yes}}
| {{ic|$HOME/.config/$desktop-mimeapps.list}} || デスクトップごとに、ユーザーが定義します
 
 
|-
 
|-
  +
|{{man|1p|mimeopen}} || {{Pkg|perl-file-mimeinfo}} || {{Yes}} || {{No}} || {{No}}
| {{ic|$HOME/.config/mimeapps.list}} || ユーザーが定義します
 
 
|-
 
|-
  +
|mimeo || {{AUR|mimeo}} || {{Yes}} || {{Yes}} || {{Yes}}
| {{ic|/etc/xdg/$desktop-mimeapps.list}} || デスクトップごとに、システム管理者やソフトウェアが定義します
 
 
|-
 
|-
  +
|whippet || {{AUR|whippet}} || {{Yes}} || {{No}} || {{Yes}}
| {{ic|/etc/xdg/mimeapps.list}} || システム管理者やソフトウェアが定義します
 
 
|-
 
|-
  +
|linopen || {{AUR|linopen}} || {{No}} || {{Yes}} || {{Yes}}
| {{ic|$HOME/.local/share/applications/$desktop-mimeapps.list}} || デスクトップごとに、互換性のために存在しますが現在は非推奨です
 
 
|-
 
|-
  +
|mimi || {{AUR|mimi-git}} || {{No}} || {{No}} || {{Y|partly}}
| {{ic|$HOME/.local/share/applications/mimeapps.list}} || 互換性のために存在しますが現在は非推奨です
 
 
|-
 
|-
  +
|busking || {{AUR|busking-git}} || {{No}} || {{Yes}} || {{Yes}}
| {{ic|/usr/local/share/applications/$desktop-mimeapps.list}} と <br>{{ic|/usr/share/applications/$desktop-mimeapps.list}} || ディストリビューションによるデフォルト、デスクトップごと
 
 
|-
 
|-
  +
|sx-open || {{AUR|sx-open}} || {{No}} || {{Yes}} || {{Yes}}
| {{ic|/usr/local/share/applications/mimeapps.list}} と <br>{{ic|/usr/share/applications/mimeapps.list}} || ディストリビューションによるデフォルト
 
  +
|-
  +
|{{man|1|rifle}} || [[ranger]] || {{No}} || {{Yes}} || {{No}}
  +
|-
  +
|handlr || {{AUR|handlr-bin}} || {{Yes}} || {{No}} || {{Yes}}
 
|}
 
|}
   
  +
=== xdg-open ===
上の表にある、{{ic|$VARS}} は環境変数で {{ic|$desktop}} は使用しているデスクトップの名前です (小文字)。例: {{ic|kde}}, {{ic|gnome}}, {{ic|xfce}}, etc。
 
   
  +
[[xdg-open]] (part of [[xdg-utils]]) implements [[XDG MIME Applications]] and is used by many programs.
特定の MIME タイプのデフォルトアプリケーションを指定するには {{ic|mimeapps.list}} ファイルの {{ic|[Default Applications]}} グループに記述します。以下の例では、{{ic|mimetype1}} ではアプリケーション {{ic|default1.desktop}} または (default1 がインストールされていない場合) {{ic|default2.desktop}} が使われます:
 
   
  +
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 {{ic|/usr/bin/xdg-open}} executable, thus changing the default application behavior of most applications. Others simply provide an alternative method of choosing default applications.
[Default Applications]
 
mimetype1=default1.desktop;default2.desktop
 
   
  +
=== perl-file-mimeinfo ===
アプリケーションはセミコロンで区切って [http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#desktop-file-id デスクトップファイル ID] を使って指定します。
 
 
In the absence of such an entry, the next {{ic|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 {{ic|mimeapps.list}} files:
 
 
[Added Associations]
 
mimetype1=foo1.desktop;foo2.desktop;foo3.desktop
 
mimetype2=foo4.desktop
 
[Removed Associations]
 
mimetype1=foo5.desktop
 
 
The {{ic|[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 {{ic|[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 {{ic|[Default Applications]}} should also be considered to add an association between application and MIME-type in the same manner.
 
 
{{Note|
 
* Arch Linux itself does not provide any system-wide preferences for associations, but other distributions and specific desktop environments may do so via {{ic|mimeapps.list}} or the older but deprecated {{ic|defaults.list}} files.
 
* デフォルトアプリケーションの設定に関する仕様は最近変更されたばかりであり、全てのプログラムが仕様に準拠しているわけではありません。事実、freedesktop.org の {{Pkg|xdg-utils}} パッケージに含まれているプログラムでさえ彼らが決めた仕様に完全には従っていないものがあります。
 
* Your choice of desktop environment, or none, will also affect how your default applications are stored.
 
* When the program {{ic|update-desktop-database}} is run (usually as root during the (un)installation of a package), it updates files called {{ic|mimeinfo.cache}} in the {{ic|/usr/local/share/applications}} and {{ic|/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]] の標準ファイルマネージャである {{pkg|thunar}} を使ってデフォルトアプリケーションを設定するには:
 
 
* 設定したいファイルタイプを持つファイルを {{ic|右クリック}} する
 
* {{ic|Open with another application}} を選ぶ
 
* 所望のアプリケーションを選ぶ
 
* {{ic|Use as default for this kind of file}} チェックボックスにチェックが入っているか確認する
 
* {{ic|Open}} ボタンをクリックする
 
 
[[PCManFM]] や {{pkg|spacefm}} のような、他のほとんどのファイルマネージャでも一般的な手順は非常に似ています。
 
 
=== Gnome Control Center ===
 
 
If it's installed, run {{ic|gnome-control-center}}, open {{ic|System}} &gt; {{ic|Details}} &gt; {{ic|Default Applications}}.
 
 
=== gnome-defaults-list ===
 
 
{{AUR|gnome-defaults-list}} is available from the [[AUR]], and contains a list of file-types and programs specific to the GNOME desktop. The list is installed to {{ic|/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 {{ic|totem}} can be replaced with another, such as {{ic|vlc}}. Save the file to {{ic|~/.local/share/applications/defaults.list}}.
 
 
=== xdg-open ===
 
   
  +
{{Pkg|perl-file-mimeinfo}} provides the tools {{man|1p|mimeopen}} and {{man|1p|mimetype}}. These have a slightly nicer interface than their {{pkg|xdg-utils}} equivalents:
[[xdg-open]] はデフォルトアプリケーションを起動するためのデスクトップ非依存のツールです。多くのアプリケーションは内部的に {{ic|xdg-open}} コマンドを呼び出しています。xdg-open は xdg-mime を使って {{ic|~/.local/share/applications/mimeapps.list}} (他のファイルも使います。GNOME, KDE, LXDE などのメインストリームになっている DE を使っている場合、xdg-open は xdg-mime より先にデスクトップ環境のツールを試行します) から、開こうとしているファイルの MIME タイプと、その MIME タイプに関連付けられているデフォルトアプリケーションを確認します。
 
  +
# 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 {{ic|file}} instead of {{ic|mimetype}} for MIME type detection if it does not detect your [[デスクトップ環境]]. This is important because {{ic|file}} does not follow the XDG standard.
詳しくは [[xdg-open]] を見てください。
 
   
  +
{{Note|{{pkg|perl-file-mimeinfo}} before 0.28-1 did not ''entirely'' follow the XDG standard. For example it did not not read [https://github.com/mbeijen/File-MimeInfo/issues/20 distribution-wide defaults] and it saved its config in [https://github.com/mbeijen/File-MimeInfo/issues/8 deprecated locations].}}
=== ファイルの関連付けのカスタマイズ ===
 
   
  +
=== mimeo ===
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 {{ic|*.foo}} files. This will only affect the current user.
 
   
  +
{{aur|mimeo}} provides the tool {{ic|mimeo}}, which unifies the functionality of {{ic|xdg-open}} and {{ic|xdg-mime}}.
First, create the file {{ic|~/.local/share/mime/packages/application-x-foobar.xml}}:
 
   
  +
# determine a file's MIME type
$ mkdir -p ~/.local/share/mime/packages
 
  +
$ mimeo -m photo.jpeg
$ cd ~/.local/share/mime/packages
 
  +
photo.jpeg
$ touch application-x-foobar.xml
 
  +
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:
Then edit {{ic|~/.local/share/mime/packages/application-x-foobar.xml}} and add this text:
 
   
  +
# open youtube links in VLC without opening a new instance
{{bc|<nowiki>
 
  +
vlc --one-instance --playlist-enqueue %U
<?xml version="1.0" encoding="UTF-8"?>
 
  +
^https?://(www.)?youtube.com/watch\?.*v=
<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>
 
</nowiki>}}
 
   
  +
{{aur|xdg-utils-mimeo}} patches ''xdg-utils'' so that {{ic|xdg-open}} falls back to mimeo if no desktop environment is detected.
Note that you can use any icon, including one for another application.
 
   
  +
=== whippet ===
Next, edit or create the file {{ic|~/.local/share/applications/foobar.desktop}} to contain something like:
 
   
  +
{{aur|whippet}} provides the tool {{ic|whippet}}, which is similar to {{ic|xdg-open}}. It has X11 integration by using {{pkg|libnotify}} to display errors and {{pkg|dmenu}} to display choices between applications to open.
{{bc|<nowiki>
 
[Desktop Entry]
 
Name=Foobar
 
Exec=/usr/bin/foobar
 
MimeType=application/x-foobar
 
Icon=foobar
 
Terminal=false
 
Type=Application
 
Categories=AudioVideo;Player;Video;
 
Comment=
 
</nowiki>}}
 
   
  +
# open a file with its default application
Note that Categories should be set appropriately for the application type (in this example, a multimedia app).
 
  +
$ 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.
Now update the applications and mime database with:
 
   
  +
=== handlr ===
$ update-desktop-database ~/.local/share/applications
 
$ update-mime-database ~/.local/share/mime
 
   
  +
{{aur|handlr-bin}}, written in Rust, provides the functionality of {{ic|xdg-open}} and {{ic|xdg-mime}} with a streamlined interface.
Programs that use mime types, such as file managers, should now open {{ic|*.foo}} files with foobar. (You may need to restart your file manager to see the change.)
 
   
  +
Compared to {{ic|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 {{ic|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
.desktop ファイルの {{ic|OnlyShowIn}} フィールドを利用することができます。[http://standards.freedesktop.org/menu-spec/latest/ このページ] を見て下さい。
 
  +
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
   
  +
{{aur|xdg-utils-handlr}} provides an {{ic|xdg-open}} that uses {{ic|handlr}} under the hood to replace {{ic|xdg-utils}}.
== 環境変数を使う ==
 
   
  +
=== Minimalist replacements ===
グラフィカルでないプログラムのほとんどは {{ic|EDITOR}} や {{ic|BROWSER}} などの[[環境変数]]を使います。環境変数はターミナルの自動起動ファイルで設定できます (例: {{ic|~/.bashrc}}):
 
   
  +
The following packages conflict with and provide {{Pkg|xdg-utils}} because they provide their own {{ic|/usr/bin/xdg-open}} script.
{{hc|~/.bashrc|<nowiki>
 
export EDITOR="nano"
 
export BROWSER="firefox"
 
</nowiki>}}
 
   
  +
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|linopen}} - 170-line Bash script, supports regex rules
=== (ファイルマネージャにある) コンテキストメニューの「他のアプリケーションで開く」でアプリケーションが表示されない ===
 
  +
* {{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
   
  +
==== run-mailcap ====
ときどき、右クリックの''他のアプリケーションで開く''ダイアログに特定のアプリケーションが表示されないことがあります。この問題を修正するには、{{Ic|/usr/share/applications}} にある {{Ic|.desktop}} ファイルを探して、root で編集し、{{Ic|1=<nowiki>Exec=</nowiki>}} 行の末尾に {{Ic|%U}} を追加してください。例えば Kile の場合、{{Ic|/usr/share/applications/kde4/kile.desktop}} を編集して {{Ic|1=<nowiki>Exec=kile</nowiki>}} という行を {{Ic|1=<nowiki>Exec=kile %U</nowiki>}} と変更する必要があります。この問題に気づいたときは、上流のプロジェクトにバグの報告をするようにしてください。
 
   
  +
{{Warning|If you use {{AUR|run-mailcap}}, it is possible for {{ic|xdg-open}} to delegate to it. This will cause an infinite loop if you are using the {{ic|/etc/mailcap}} from {{Pkg|mailcap}}, because it also delegates to {{ic|xdg-open}}.}}
You may also have to edit the {{Ic|MimeType}} list in the {{Ic|.desktop}} file if you install extensions that allow an application to handle additional MIME types.
 

2021年8月25日 (水) 10:16時点における版

プログラムはさまざまな方法でデフォルトのアプリケーションの関連付けを実装します。コマンドラインプログラムは伝統的に環境変数を使いますが、グラフィカルアプリケーションでは、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.

リソースオープナー

  • 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.