11

The various Linux's desktops open files according to their mime type. This is a very nice feature but I also need to open them by extension (as with Windows).

For instance, I want to open every xxxxx.vnc files with a specific program when I double-click on them.
I use xfce but I don't think it differs from Gnome or KDE because all of them use the same configuration files (defaults.list and mimeapps.list).
If possible the settings are user specific, not system wide.

I've found some very poor informations about that, and all are system wide, so may be wiped out by some updates.

Indrek
  • 24,204
  • 14
  • 90
  • 93
Gregory MOUSSAT
  • 901
  • 4
  • 17
  • 39
  • Why do you need extension and not mime type? Do you have a file that is for example a .png, but [file(1)](http://unixhelp.ed.ac.uk/CGI/man-cgi?file) returns a different mime type for? – Justin Dearing Aug 09 '12 at 18:19
  • Why do you think this question is off topic @JustinDearing? AFAICT, this question is perfectly on topic on Super User, as it concerns computer software. Unless Gregory himself decides he wants it migrated somewhere else, it should stay here. – Daniel Beck Aug 09 '12 at 18:23
  • I flagged this question as off topic, it belongs on [unix.stackexchange.com](http://unix.stackexchange.com) – Justin Dearing Aug 09 '12 at 18:29
  • @DanielBeck I meant no offense. I thought that would be a better place for it. I flagged it, the moderators can decide. As you can tell, I did provide helpful comments, and depending on his responses I will try to provide an answer to the best of my abilities. – Justin Dearing Aug 09 '12 at 18:30
  • @JustinDearing I saw that flag, and that's why I asked — I could have be missing something that makes this off topic. I saw that you did not mean to "steal" the question, as many others do, easily identified by high-rep accounts on the supposed destination site. We have a lot of users on this site that can answers related to Unix/Linux though, so there's no reason to move it yet. The situation's different if no responses are posted for a week or so. – Daniel Beck Aug 09 '12 at 18:36
  • @JustinDearing Note that *many* users will interpret comments such as yours above to mean they should ask on the other site as well, thereby creating a cross-post, something that is frowned upon on the SE network and negating your original helpful intentions. That's why I deleted it. – Daniel Beck Aug 09 '12 at 18:40
  • IMHO the question could have better answers if placed unix.stackexchange.com (which I didn't knew about). – Gregory MOUSSAT Aug 09 '12 at 20:52
  • @GregoryMOUSSAT Do you want to have this question migrated? If so, please flag your answer and request migration in the text box, a moderator will then consider the request. – Daniel Beck Aug 10 '12 at 17:20

1 Answers1

10

The answer is simple but can't be guessed:

  1. Create a file named vnc-mime.xml (whatever name, but must obey some patern)

  2. Inside the file:

    <?xml version="1.0"?>  
    <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>  
        <mime-type type="application/extension-vnc">  
            <comment>.vnc file</comment>  
            <glob pattern="*.vnc"/>  
        </mime-type>  
    </mime-info>  
    
  3. Run "xdg-mime install vnc-mime.xml" as the local user. (or as root for the settings to be system-wide? Not tested)

  4. The mime type is now registered. Use your favorite file manager to select the program you want to run (with "Open as...")

Bertrand SCHITS
  • 1,043
  • 2
  • 9
  • 14
  • 3
    Bertrand, I cleaned up the XML in your answer for you. You can see how I did it by clicking the edit button. I used a code block to provide a fixed-width font and to stop processing of angle brackets or other markdown/formatting. The [markdown formatting guide](http://superuser.com/editing-help) has some wonderful examples of all the advanced things you can do in markdown. Hope that helps! – Darth Android Aug 10 '12 at 17:20
  • Is there a commend-line version for this? I want to automatically open files based on their type from typing into an xterm. – Eyal Nov 27 '12 at 13:32
  • before it works (step 4) you maybe have to kill all running file managers. for me i had to `killall nemo` – iRaS Mar 17 '16 at 07:12