Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
Why do you need extension and not mime type? Do you have a file that is for example a .png, but file(1) returns a different mime type for? –  Justin Dearing Aug 9 '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 9 '12 at 18:23
    
I flagged this question as off topic, it belongs on unix.stackexchange.com –  Justin Dearing Aug 9 '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 9 '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 9 '12 at 18:36
show 3 more comments

1 Answer

up vote 4 down vote accepted

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...")
share|improve this answer
1  
Thanks, this works. –  Gregory MOUSSAT Aug 10 '12 at 16:25
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 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.