Difference between revisions of "Default applications"

From ArchWiki
Jump to: navigation, search
(Gnome 3)
(How it should work)
(29 intermediate revisions by 8 users not shown)
Line 1: Line 1:
{{Stub}}
+
[[Category:Desktop environments]]
{{Poor writing}}
+
[[zh-cn:Default Applications]]
 +
{{Merge|Custom File Associations|current contents of this article are better but title is worse}}
 +
{{Expansion|It would be good to have detailed explanations for other DEs as well.}}
 +
 
 
There are numerous places to configure default applications on Linux. This page will attempt to address problems related to the following issues:
 
There are numerous places to configure default applications on Linux. This page will attempt to address problems related to the following issues:
 
* You need to change a certain default application (e.g. after switching desktop environments), but there appears to be nowhere to configure it, or an application ignores your configuration
 
* You need to change a certain default application (e.g. after switching desktop environments), but there appears to be nowhere to configure it, or an application ignores your configuration
 
* You regularly switch back and forth between several desktop environments, and need to configure some applications (e.g. file manager) on a per-desktop-environment basis, but need to configure others (e.g. web browser) globally
 
* You regularly switch back and forth between several desktop environments, and need to configure some applications (e.g. file manager) on a per-desktop-environment basis, but need to configure others (e.g. web browser) globally
  
Until there is more information/organization, it will just be a dumping ground of random tricks
+
== Changing a default application ==
 +
=== xdg-open ===
 +
[[xdg-open]] is a desktop-independent tool for configuring default applications.
  
==Changing a default application ==
+
==== Exactly how it works ====
===xdg-open===
+
This is currently very shaky because the standard in question ([http://www.freedesktop.org/wiki/Specifications/mime-actions-spec relevant freedesktop.org document], "Default application ordering" section) is still not finalised and it is even less correctly implemented.
The {{Codeline|xdg-open}} command uses the {{filename|~/.local/share/applications/mimeapps.list}} file to pick which application to use. Many applications invoke this command internally, so this may be the best place to look. Its contents refer to the {{filename|.desktop}} files located in /usr/share/applications/. KDE applications are located in the {{filename|kde4}} subdirectory and are referred to by prefixing {{filename|kde4-}} to the {{filename|.desktop}} file's name (e.g. {{filename|kde4-dolphin.desktop}}).
+
 
 +
What happens with the current version of xdg-open (extra/xdg-utils 1.1.0rc1-3) is the following: xdg-open uses xdg-mime (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. xdg-mime looks for the default application in the following files:
 +
 
 +
/usr/share/applications/defaults.list      (global)
 +
~/.local/share/applications/defaults.list  (per user, overrides global)
 +
 
 +
The syntax of these files is:
  
{{filename|mimeapps.list}} lists applications in order of preference; if the first listed application is not installed, the second one will be used. Its format is as follows:
 
...
 
 
  [Default Applications]
 
  [Default Applications]
  mimetype=desktopfile1;desktopfile2...
+
  mimetype=desktopfile1;desktopfile2;...;desktopfileN
For example,
+
 
 +
E.g.
 +
 
 
  [Default Applications]
 
  [Default Applications]
  text/html=firefox.desktop
+
  text/html=firefox.desktop;chromium.desktop
inode/directory=kde4-dolphin.desktop;Thunar.desktop;nautilus.desktop
+
  
The best way to look up the MIME type is to read the {{Codeline|MimeTypes}} list in your application's {{filename|.desktop}} file.
+
The intent is to be able to specify applications in order of preference so the next would be selected if the previous is unavailable. However, xdg-open is currently '''broken''' and specifying more than one application for a single MIME type will result in none being used. Be sure to specify only '''one''' application per MIME type.
  
You shouldn't mess with the {{Codeline|[Added Associations]}} section, but see [[#Exactly how the config files mesh together|Exactly how the config files mesh together]] if you do. There is also a {{filename|/usr/share/applications/mimeapps.list}} that doesn't exist on Arch by default which you also probably shouldn't mess with.
+
Also see [[xdg-open]] for more information on what affects its behaviour. This information is sufficient for a user to configure default applications on Arch currently.
  
You can put custom {{filename|.desktop}} files into {{filename|~/.local/share/applications}}.
+
==== How it should work ====
 +
However, the behaviour described in the previous section is actually wrong according to the quoted standard draft. defaults.list should only be used by distributions/DEs to specify sane defaults for that particular environment. This file should only be placed in {{Ic|/usr/share/applications/}}, it should be a system-wide setting and it should not be changed by users. Instead, users should use the files {{ic|/usr/share/applications/mimeapps.list}} (global) and {{ic|~/.local/share/applications/mimeapps.list}} (per user, overrides global) to specify custom file associations. The syntax of these files is as follows:
 +
{{hc|mimeapps.list|
 +
[Added Associations]
 +
mimetype=desktopfile1;desktopfile2;...;desktopfileN
 +
...
 +
[Removed Associations]
 +
mimetype=desktopfile1;desktopfile2;...;desktopfileN
 +
}}
  
===Gnome 3===
+
The [Added Associations] section is used to specify preferred (default) applications in decreasing order of preference for the specified MIME type. The [Removed Associations] section is used to explicitly remove any previously inherited associations.
====xdg-open====
+
The file {{filename|~/.local/share/applications/defaults.list}} has the same syntax as {{filename|mimeapps.list}}. You can use it instead of {{filename|mimeapps.list}}, but it's probably best to use {{filename|mimeapps.list}}; see [[#Exactly how the config files mesh together|Exactly how the config files mesh together]].
+
  
Sometimes, a certain application will not appear in the right-click ''Open With...'' dialog. To fix this problem, locate the {{filename|.desktop}} file in {{filename|/usr/share/applications}}, edit it as root, and add {{Codeline|%U}} to the end of the {{Codeline|1=<nowiki>Exec=</nowiki>}} line. For example, Kile currently has this problem; you need to edit {{filename|/usr/share/applications/kde4/kile.desktop}} and change the line reading {{Codeline|1=<nowiki>Exec=kile</nowiki>}} to read {{Codeline|1=<nowiki>Exec=kile %U</nowiki>}}. Also, please file a bug against the upstream project if you notice this problem.
+
Note that the upstream, yet unreleased xdg-utils were fixed to use mimeapps.list instead of defaults.list but the xdg-open bug (specifying multiple applications breaks it completely) still remains.
  
You may also have to edit the {{Codeline|MimeTypes}} list in the {{filename|.desktop}} file if you install extensions that allow an application to handle additional MIME types.
+
Currently, the best option is to use {{AUR|mimeo}}, which implements everything explained above correctly.  There is also {{AUR|xdg-utils-mimeo}} which provides a patched xdg-open to use mimeo. Both are available in [[Arch User Repository|AUR]].
  
====GConf====
+
=== Gnome 3 ===
As far as I can tell, on Gnome 3, there are two configuration systems, GConf (older) and dconf (newer). GConf can be configured with {{Codeline|gconf-editor}}; in particular, you can try messing with the {{filename|/desktop/gnome/applications/}} key, but changing settings there didn't fix any problems I had. dconf can be configured with the {{Codeline|gsettings}} command.
+
The xdg-open settings are usually recognized by Gnome, but if they aren't, there are still other methods.
  
====Terminal====
+
==== GConf ====
 +
As far as I can tell, on Gnome 3, there are two configuration systems, GConf (older) and dconf (newer). GConf can be configured with {{Ic|gconf-editor}}; in particular, you can try messing with the {{ic|/desktop/gnome/applications/}} key, but changing settings there didn't fix any problems I had. dconf can be configured with the {{Ic|gsettings}} command.
 +
 
 +
==== Terminal ====
 
To configure the default terminal for the package ''nautilus-open-terminal'' to Konsole, use
 
To configure the default terminal for the package ''nautilus-open-terminal'' to Konsole, use
 
  $ gsettings set org.gnome.desktop.default-applications.terminal exec konsole
 
  $ gsettings set org.gnome.desktop.default-applications.terminal exec konsole
 
  $ gsettings set org.gnome.desktop.default-applications.terminal exec-arg "'-e'"
 
  $ gsettings set org.gnome.desktop.default-applications.terminal exec-arg "'-e'"
The second command tells {{Codeline|konsole}} to expect a command to be passed to it as part of the invocation. ''nautilus-open-terminal'' needs this because it passes a {{Codeline|cd}} command in order to switch to the appropriate directory. For example, opening a terminal in your {{filename|~/Desktop}} directory will invoke something like
+
The second command tells {{Ic|konsole}} to expect a command to be passed to it as part of the invocation. ''nautilus-open-terminal'' needs this because it passes a {{Ic|cd}} command in order to switch to the appropriate directory. For example, opening a terminal in your {{Ic|~/Desktop}} directory will invoke something like
 
  $ konsole -e cd "~/Desktop"
 
  $ konsole -e cd "~/Desktop"
====Web browser====
+
 
 +
==== Web browser ====
 
To configure the web browser used by the AUR package ''gnome-gmail-notifier'', run
 
To configure the web browser used by the AUR package ''gnome-gmail-notifier'', run
 
  $ gconf-editor
 
  $ gconf-editor
and edit the {{filename|/desktop/gnome/url-handlers/http/}} key. You may want to change {{filename|https/}}, {{filename|about/}}, and {{filename|unknown/}} keys while you're at it.
+
and edit the {{ic|/desktop/gnome/url-handlers/http/}} key. You may want to change {{ic|https/}}, {{ic|about/}}, and {{ic|unknown/}} keys while you're at it.
  
====Exactly how the config files mesh together====
+
== Maintaining settings for multiple desktop environments ==
This is not necessary reading, but here is, as nearly as I can tell, the precedence order for the various config files, from high to low:
+
The {{ic|OnlyShowIn}} field of a .desktop file may be useful; see [http://standards.freedesktop.org/menu-spec/latest/ this page]. I haven't tried setting this field yet; please update this wiki page if you have any info about using {{ic|OnlyShowIn}}.
~/.local/share/applications/mimeapps.list, [Default Applications] section
+
~/.local/share/applications/mimeapps.list, [Added Applications] section
+
~/.local/share/applications/defaults.list
+
/usr/share/applications/mimeapps.list, [Default Applications] section
+
/usr/share/applications/mimeapps.list, [Added Applications] section
+
/usr/share/applications/defaults.list
+
Note that ordinarily, if a higher-precedence config file (or config file section) specifies an application that is not installed, it will fall-back to a lower-precedence config file (or section). However, if a non-existent application is specified in any {{filename|~/.local/}} file, then all of the {{filename|/usr/}} files will be ignored for that MIME type.
+
  
See also [http://www.freedesktop.org/wiki/Specifications/mime-actions-spec this page on freedesktop.org], "Default application ordering" section.
+
== Troubleshooting ==
 +
=== Applications don't appear in the ''Open With...'' context menu (of a file manager) ===
 +
Sometimes, a certain application will not appear in the right-click ''Open With...'' dialog. To fix this problem, locate the {{Ic|.desktop}} file in {{Ic|/usr/share/applications}}, edit it as root, and add {{Ic|%U}} to the end of the {{Ic|1=<nowiki>Exec=</nowiki>}} line. For example, Kile currently has this problem; you need to edit {{Ic|/usr/share/applications/kde4/kile.desktop}} and change the line reading {{Ic|1=<nowiki>Exec=kile</nowiki>}} to read {{Ic|1=<nowiki>Exec=kile %U</nowiki>}}. Also, please file a bug against the upstream project if you notice this problem.
  
==Maintaining settings for multiple desktop environments==
+
You may also have to edit the {{Ic|MimeTypes}} list in the {{Ic|.desktop}} file if you install extensions that allow an application to handle additional MIME types.
More info later...
+

Revision as of 17:12, 20 October 2012

Merge-arrows-2.pngThis article or section is a candidate for merging with Custom File Associations.Merge-arrows-2.png

Notes: current contents of this article are better but title is worse (Discuss in Talk:Default applications#)

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: It would be good to have detailed explanations for other DEs as well. (Discuss in Talk:Default applications#)

There are numerous places to configure default applications on Linux. This page will attempt to address problems related to the following issues:

  • You need to change a certain default application (e.g. after switching desktop environments), but there appears to be nowhere to configure it, or an application ignores your configuration
  • You regularly switch back and forth between several desktop environments, and need to configure some applications (e.g. file manager) on a per-desktop-environment basis, but need to configure others (e.g. web browser) globally

Changing a default application

xdg-open

xdg-open is a desktop-independent tool for configuring default applications.

Exactly how it works

This is currently very shaky because the standard in question (relevant freedesktop.org document, "Default application ordering" section) is still not finalised and it is even less correctly implemented.

What happens with the current version of xdg-open (extra/xdg-utils 1.1.0rc1-3) is the following: xdg-open uses xdg-mime (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. xdg-mime looks for the default application in the following files:

/usr/share/applications/defaults.list      (global)
~/.local/share/applications/defaults.list  (per user, overrides global)

The syntax of these files is:

[Default Applications]
mimetype=desktopfile1;desktopfile2;...;desktopfileN

E.g.

[Default Applications]
text/html=firefox.desktop;chromium.desktop

The intent is to be able to specify applications in order of preference so the next would be selected if the previous is unavailable. However, xdg-open is currently broken and specifying more than one application for a single MIME type will result in none being used. Be sure to specify only one application per MIME type.

Also see xdg-open for more information on what affects its behaviour. This information is sufficient for a user to configure default applications on Arch currently.

How it should work

However, the behaviour described in the previous section is actually wrong according to the quoted standard draft. defaults.list should only be used by distributions/DEs to specify sane defaults for that particular environment. This file should only be placed in /usr/share/applications/, it should be a system-wide setting and it should not be changed by users. Instead, users should use the files /usr/share/applications/mimeapps.list (global) and ~/.local/share/applications/mimeapps.list (per user, overrides global) to specify custom file associations. The syntax of these files is as follows:

mimeapps.list
[Added Associations]
mimetype=desktopfile1;desktopfile2;...;desktopfileN
...
[Removed Associations]
mimetype=desktopfile1;desktopfile2;...;desktopfileN

The [Added Associations] section is used to specify preferred (default) applications in decreasing order of preference for the specified MIME type. The [Removed Associations] section is used to explicitly remove any previously inherited associations.

Note that the upstream, yet unreleased xdg-utils were fixed to use mimeapps.list instead of defaults.list but the xdg-open bug (specifying multiple applications breaks it completely) still remains.

Currently, the best option is to use mimeoAUR, which implements everything explained above correctly. There is also xdg-utils-mimeoAUR which provides a patched xdg-open to use mimeo. Both are available in AUR.

Gnome 3

The xdg-open settings are usually recognized by Gnome, but if they aren't, there are still other methods.

GConf

As far as I can tell, on Gnome 3, there are two configuration systems, GConf (older) and dconf (newer). GConf can be configured with gconf-editor; in particular, you can try messing with the /desktop/gnome/applications/ key, but changing settings there didn't fix any problems I had. dconf can be configured with the gsettings command.

Terminal

To configure the default terminal for the package nautilus-open-terminal to Konsole, use

$ gsettings set org.gnome.desktop.default-applications.terminal exec konsole
$ gsettings set org.gnome.desktop.default-applications.terminal exec-arg "'-e'"

The second command tells konsole to expect a command to be passed to it as part of the invocation. nautilus-open-terminal needs this because it passes a cd command in order to switch to the appropriate directory. For example, opening a terminal in your ~/Desktop directory will invoke something like

$ konsole -e cd "~/Desktop"

Web browser

To configure the web browser used by the AUR package gnome-gmail-notifier, run

$ gconf-editor

and edit the /desktop/gnome/url-handlers/http/ key. You may want to change https/, about/, and unknown/ keys while you're at it.

Maintaining settings for multiple desktop environments

The OnlyShowIn field of a .desktop file may be useful; see this page. I haven't tried setting this field yet; please update this wiki page if you have any info about using OnlyShowIn.

Troubleshooting

Applications don't appear in the Open With... context menu (of a file manager)

Sometimes, a certain application will not appear in the right-click Open With... dialog. To fix this problem, locate the .desktop file in /usr/share/applications, edit it as root, and add %U to the end of the Exec= line. For example, Kile currently has this problem; you need to edit /usr/share/applications/kde4/kile.desktop and change the line reading Exec=kile to read Exec=kile %U. Also, please file a bug against the upstream project if you notice this problem.

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