How do I set up preferred applications in Nautilus by file extension, rather than by mime type?

Solution 1:

You can use mimeopen to set what application to use to open a file based upon it's extension.

Run mimeopen followed by the file extension you want to change. For example, if I wanted to open .py (python) files in Geany instead of Gedit I would run:

mimeopen .py  

Which returns (on my system, this will depend slightly based on what software you have installed on your computer):

Please choose a default application for files of type text/x-python

1) Geany  (geany)
2) notepad  (wine-extension-txt)
3) gedit  (gedit)
4) LibreOffice 4.0 Writer  (libreoffice4.0-writer)
5) Other...

use application #  

Inputting 1 and pressing Enter will open a blank .py file in Geany and set all further .py files to open in that editor.

If I put in 5 and press Enter I get the prompt:

use command:  

In which case I can use a program's command to open whatever file type I am currently changing.

So I could have done:

mimeopen .py  

Used 5 and put geany as the command to get the same result:

You might notice that if you run mimeopen .py again it will open a new .py file in Geany (or whatever app you chose) instead of asking you what application to use. In that case you need to use the -a handle, like this:

mimeopen -a .py