Nautilus open-with / mime-type associations

Using the native GNOME file manager Nautilus, you can double-click on a file to open it with its default application. If you don’t like that, are not sure what the default application is, or want to modify it, then you can right-click on the file to see a list of mime-type associations. The first item on the list is the default application, and the rest are alternatives. The last item on the list is “Open with Other Application…”.

For example, on my current system, right-clicking on a .txt file brings up:

  Open with "Emacs Text Editor"
  Open with "OpenOffice.org Calc"
  Open with "OpenOffice.org Writer"
  Open with Other Application...

Clicking on “Open with Other Application…” brings up a dialogue box that lets you add another application to the list. A list of known applications is provided, and there is a “Use a custom command” option, that allows associating with any arbitrary command.

If you want to change the default application, or remove an application from the list, then right-click on the file, and select Properties -> Open With.

Modifying the mime-type associations manually:

Under a standard freedesktop system, the local (user) mime-type associations are listed in: ~/.local/share/applications/mimeapps.list
For example, the .txt file associations on my system are listed as follows:
[Added Associations]
text/plain=emacs.desktop;openoffice.org-calc.desktop;openoffice.org-writer.desktop;

These are references to *.desktop files, which describe the applications.

Adding applications to the “Open with Other Application…” list:

Any application manually associated with a file type using the “Use a custom command” option is automatically added to the “Open with Other Application…” known applications list. In the “back-end”, a corresponding ad-hoc *.desktop file is created to describe the application, and a reference to it is made in the mimeapps.list file.

An interesting question is: How to add an application to the default “Open with Other Application…” list using an existing *.desktop file. Doing this has the advantage of recycling existing files, automatically associating mime-types, and adding a nice icon to the application.

In fact, the default known applications list is automatically derived from the list of known *.desktop files – the same list used to derive the menu. Thus all *.desktop files in the standard locations are used to generate the list. A caveat that I discovered however, is that not all *.desktop files are included – only the ones containing a line similar to:
Exec=<command> %f
… ie, that specify how to handle a parameter (the file being opened) are included.

Example: I set up Photoshop under WINE and wanted to associate *.psd files with it. To do this:

  1. Create a shell script to run Photoshop and pass parameters to it (and test it!)
  2. Create a Photoshop.desktop file with the Exec line calling the script and passing %f
  3. Place the *.desktop file in ~/.local/share/applications (or another standard location)
  4. Use the “Open with Other Application…” dialogue as above to make the association – Photoshop should now appear on the list

Nautilus Actions Configuration

Just for good measure, under System -> Preferences -> Nautilus Actions Configuration is a method for adding context-menu actions to Nautilus. These are items that appear in the same right-click menu as above, but lower down the list (below “Search for Files…”). You can associate applications this way as well.


Sample script to run Photoshop under WINE:

#!/bin/ksh
param=
while [ "$1" ]
do
  param="$param Z:$1"
  shift
done
wine "C:\Program Files\Adobe\Adobe Photoshop CS2\Photoshop.exe" $param


Sample *.desktop file for Photoshop under WINE:

#!/usr/bin/env xdg-open

[Desktop Entry]
Encoding=UTF-8
Version=1.0
Type=Application
Terminal=false
Icon[en_US]=~/.local/share/icons/9b6a_newshortcut1_236bb7c4441942fd04091e257a25e34d.0.png
Name[en_US]=Image Editor - Photoshop
Exec=~/applications/Photoshop/Photoshop %f
Name=Image Editor - Photoshop
Icon=gnome-panel-launcher
MimeType=image/x-psd;image/vnd.adobe.photoshop;

Leave a Reply

 

 

 

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


× one = 6