How to register a shell script as the main application for a given file extension

This seems to work fine from a terminal if you do xdg-open foo.ext, however it doesn't seem to work in Nautilus unless you define your script as default for opening the *.ext file:

  • Select such a file,
  • Right-click,
  • Choose Properties,
  • Select the Open With tab,
  • Click on Show other applications,
  • Select your script (should be The script that manages .ext files),
  • Click Set as default, and finally press
  • Close.

After I did that, the script started from Nautilus.