The default application that opens a file when double-clicking it in Thunar is not well documented and the UI does not make it clear.
The fault is not all Thunar's. The implementation is rooted in the XDG specification: Association between MIME types and applications.
XDG defines the configuration files that determine the mapping from file mime type to application. Part of the problem is that the configuration of this mapping is not well defined and the specified behaviour, which Thunar exhibits, is confusing and dangerous.
The problem is that there are two parts of the configuration that are significant:
- An explicit list of default applications
- A list of applications, in 'priority' order, that handle the mime type
If the explicit default application list is set, then the first available application in that list is the default application that is run to open the file on double-click.
If the explicit default application list is not set, then the first available application in the list of applications supporting the mime type is run to open the file on double-click.
The Thunar context menu puts the name of the default application - the one that will be run on double-click, as the first entry in the context menu, preceded by 'Open with'. For example, 'Open with "Restretto Image Viewer"'.
But it does not distinguish whether this is an explicit default application or merely the first in the list of applications supporting the mime type.
The distinction is important because if one selects Open with from the context menu and selects some application, that application is moved to the head of the list of applications supporting the mime type. If there is no explicit default application, then this becomes the new default application: every time on uses Open with to open a file with a different application (e.g. Gimp Vs Restretto Image Viewer), the default changes.
If an explicit default application is set, then opening with another application via Open with does not change the default application. But the Thunar UI does not make it obvious if there is an explicit default application or not.
The file properties also show the default application but similarly do not indicate if it is an explicit default or merely the first in the list of supporting applications.
The design is dangerous because if there is an explicit default application but that application is not available (e.g. it has been removed), then the default application does not become unset - it becomes whatever happens to be first in the list of supporting applications, which depends on the history of Open with operations: essentially random, based on history.
A better design would be, on double-click:
- If there is an explicit default application, run it to open the file
- If there is no explicit default application, prompt the user to select an explicit default application and save it as the explicit default, then run it to open the file.
This ensures that the file is not opened by an essentially random application, and that the explicit default application is set if double-click is used. Also, if the explicit default application is unavailable (e.g. has been removed from the system, permission denied or whatever) then the file is not opened in some other, essentially random application. Instead, the user is prompted to select a new explicit default application.
In short: double-click should only ever run an explicit default.
The Thunar implementation and documentation makes the situation worse by not clearly describing what 'the default application' is or how it relates to the mime types and desktop application configurations.
The Thunar documentation does not describe the side effects of Open with, nor the interaction with the explicit default application.
To be very generous, this statement in the Thunar documentation regarding Open With Other Application is ambiguous to the point of being misleading:
The action you have chosen is now added to the list of Recommended Applications for that particular file type. If you enabled the Use as default for this kind of file option or there was no prior action associated with the type, the newly added action becomes the default.
The ambiguity is between default in 'Use as default for this kind of file', which sets the explicit default, and 'becomes the default'. One might think that 'becomes the default' is the same outcome as 'Use as default', but it isn't. The 'becomes the default' case merely moved the selected application to the front of the list of supporting applications. The 'Use as default' sets the application as explicit default so that the order of applications in the list of supporting applications becomes irrelevant and future changes to the order of the list of supporting applications do not change what the default application is.
And 'there was no prior action associated with the type' is simply incorrect. Even if there was a prior action (there almost always is), opening a file with Open with changes the order of the list of supporting applications, effectively changing the default application but without setting the explicit default application, unless the checkbox Use as default for this kind of file is checked.
The XDG specification allows one or more 'default' applications to be specified explicitly, for each mime type. It also allows the set of applications supporting the mime type to be specified, in order of decreasing priority.
If there is an explicit default application list, the first available application in that list (e.g. not uninstalled) is used to open the file. If there is no explicit default application, the first available application in the list of applications supporting the mime type is used to open the file.
There are multiple problems with this:
- There are multiple configuration files which may specify the applications and/or default applications associated with a mime type. Each may specify files in priority order, but it is not clearly stated how lists from multiple files are merged.
- In addition to the mimeapps.list files, there are also .desktop files, each of which can specify the set of mime types handled by the application. It is not clearly stated how these are merged with the prioritized list of applications for a mime type.
- In addition to the configuration files, there are cache files. The specification says nothing about them but the implementation uses them, but it is not clearly stated how the contents of the cache files are derived and/or merged with the configuration files.
- If the explicit default application is not available (e.g. has been removed) then the file is opened with the first application in the list of applications supporting the mime type. But this could be a totally inappropriate application to be used by default. For example, Thunar sets whatever is selected as 'Open with' as the highest priority. So something that was used just once, on one particular file, can become the default used on double-click.
- Thunar has a 'Use as default' checkbox in the 'Open with' dialog. If this is checked, then the explicit default application is set. What is confusing is that if this is not checked and there is no explicit default, then the explicit default application is not set but the selected application becomes the default for double-click none the less, because the selected application becomes first in the list of supporting applications.
XDG specifies a very dysfunctional and dangerous algorithm for determining the Default Application.
The problem is:
Once all levels have been checked, if no entry could be found, the implementation should pick the most-preferred .desktop files associated with the mimetype, taking into account added and removed associations as per the previous section.By 'most-preferred', one can only guess: the term isn't defined. The section Adding/removing associations provides and algorithm for listing applications 'in preference order' but it doesn't define how lists from multiple files are merged. Presumably the are appended, but this isn't stated. It doesn't define how duplicates (i.e. the same association specified in multiple mimeapps.list files) should be handled.
When associations are added from .desktop files with MimeType= including the given mime type, the specification does not say in what order these should be added.
As a result, the 'preferred order' is not well specified.
So, if no 'Default Application' has been specified in any 'mimeapps.list file, then the default application is the 'most-preferred' one in the list that does not have a well defined order.
Double clicking a file can open it with an appropriate app, then after some change (add/remove software, or whatever change) if that app can't be found for some reason, an effectively random app is used, instead of alerting the user that the default app cannot be found and forcing an explicit selection. This is dangerous.
The problem is that Thunar does nothing to clarify or disambiguate what will happen on double-click.
When you double-click a file, it is opened with a 'default' application - that is, without specifying an application, some application is used to open the file. I call that a 'default' application.
In fact, when one double-clicks, there are two cases:
- A 'Default Application' has been set and that is used to open the file
- No 'Default Application' has been set, in which case whatever application was last used to open the mime type of the file is used
That second case is the problem. The 'whatever application was last used' is effectively a default application, except that it is not saved as the 'Default Application' so that every time 'Open with...' is used to select a different application, without checking 'Use as default', the effective default application (i.e. whatever was used last) changes.
The two kinds of default are not well documented and the magic behaviour of 'Use as default' is not documented. The fact that there are two ways of determining the default application is not documented. Users are left with this unexplained, confusing behaviour.
The behaviour should be documented at Thunar - Working with Files and Folders, but it isn't. Instead, there are statements about 'the default action' without any clarification about the different kinds of default action or how to set them. Nothing is said at all about the difference between 'the default action' and the 'Default Action'.
See "Open with" always changes default
The Thunar 'Open with...' interface does not clearly indicate whether there is a 'Default Application' or not. It shows a list of applications that may be selected and one is the effective default but there is no distinction in the presentation between it being the configured 'Default Application' or merely the last application used.
To see the 'Default Application' for a mime type, it is necessary to open ~/.config/mimeapps.list and look for the section [Default Applications]. If the mime type is listed in this section, then it has a 'Default Application'. Otherwise, it just has whatever was used last.
The context menu option 'Set default application' sets the 'Default Application' and it also, despite the name, opens the file with the new 'Default Application'. It does not, as the name implies, merely change the default application.
The context menu option 'Open with other application...', with the checkbox 'Use as default for this kind of file' is redundant with 'Set default application': it changes the 'Default Application' and opens the file with the new 'Default Application'.
The file properties shows 'Open with:' but does not indicate whether the application is the 'Default Application' or merely 'the default application' - i.e. the application that was last used to open the type.
If you add a 'Custom Command', these are stored in '.desktop' files in ~/.local/applications. The file names begin with 'userapp-'.
Even worse: Open with > Open With Other Application... opens a dialog with title 'Open With' that has at the top an application under the heading 'Default Application' even when there is no 'Default Application' - there is only the application that was last used. This makes it totally confusing as to whether there is a 'Default Application' or not and makes the behaviour of selecting a different application with 'Open with' extremely mysterious. It is stupid by design.
You can delete .desktop files in ~/.local/applications, but then you must run 'update-desktop-database ~/.local/applications' to rebuild the cache of mime type / application associations. It is not clear what happens if an entry in ~/.config/mimeapps.list refers to a desktop file that has been deleted.
What would be a not-stupid design: If there is no default, then there is no default - double clicking a file with no default application should open a pop-up dialog that tells the user there is no default application so the double-click cannot open the file. The right click context menu should show a list of options for opening the file with none distinguished as the default application. On the other hand, if there is a default application, the right click context menu should clearly indicate the default application, and other options for opening the file.