I have a file called foo.txt. I want to associate my own program with the mime-type .txt so that my program opens a terminal and shows the contents of foo.txt as standard output. I would prefer Ruby, but BASH scripting will also be OK.

An working example: I can open an HTML file with firefox. I want to open txt files with my own executable the same way.

I can't figure out how can I actually get it working?

Example 2: I can open a .txt file with Geany/Mousepad/Atom/Code etc. Let's suppose I have made a tool just like mousepad. How should my program handle the .txt mimetype?

So far I have made a small GUI program with Ruby and made it executable and tried to open foo.txt with my program (I used the Nemo file manager). I have captured arguments, and stdins in my Ruby program so it will show the Argument and STDINs if any. But my program doesn't even show up the window if I open a .txt file with it!

How am I supposed to achieve the result?

  • To be clear, you have right clicked on the file and selected Open With > Other Application and selected your custom application and that does not work? What happens specifically? When you use your custom application can you open files with it? – kemotep Mar 6 at 22:02
  • Yes. I am using a simple Ruby GUI program (with Ruby2D) The custom command is a GUI application that shows the arguments given, the base name of the script. It runs normally from the terminal, but doesn't open when I 'open as' with that. Also, I have proper permissions, and I am using a single user. – S.Goswami Mar 7 at 8:20
  • What operating system are you using? You may need to change the values or import them from ~/.local/share/applications/mimeapps.list to have Nemo recognize the change. – kemotep Mar 7 at 18:23
  • 1
    Your Ruby GUI program is able to open up files, its Nemo not opening said files using your choice of filetype association? Is that the issue? Or is the issue that your Ruby program does not open up files? If the latter is the issue this question would be better served on Stack Overflow. – kemotep Mar 8 at 1:03
  • 1
    If "Opens a terminal and shows the contents of foo.txt as standard output" are all done inside your program, and your program support command line parameters like program filename, then you can simply create a desktop file for your program, and set mime association through your DE settings. – 炸鱼薯条德里克 Mar 8 at 16:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.