views:

3066

answers:

4

I'm developing a Linux application that has its own file format. I want my app to open when you double-click on those files.

How can I register a file extension and associate it with my application on Linux? I'm looking for a way that that is standard (works with GNOME and KDE based systems) and can be done automatic when my program is installed or run for the first time.

+3  A: 

1) in linux this is a function of your desktop environment rather than the os itself.
2) GNOME and KDE have different methods to accomplish this.
3) There's nothing stopping you from doing it both ways.

Joel Coehoorn
A: 

GNOME and KDE are very different... don't count on finding a single solution.... you might get by with sticking appropriate files into:

/usr/share/mime-info/

Alternatively use the 'shebang' method and update your "file format" so that the first line can be:

#!/bin/yourapp

Then make sure all your files are marked executable and that your app doesn't get installed somewhere else ;)

sascha
+3  A: 

There are two parts to this. You need to register a new file type and then create a desktop entry for your application. The desktop entry associates your application with your new mime type.

I thought that both Gnome and KDE (maybe only 4+?) used the freedesktop shared mime info spec, but I may well be wrong.

Kai
+11  A: 

Use xdg-utils from freedesktop.org Portland.

Register the icon for the MIME type:

xdg-icon-resource install --context mimetypes --size 48 myicon-file-type.png x-application-mytype

Create a configuration file (freedesktop Shared MIME documentation):

<?xml version="1.0"?>
 <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'&gt;
   <mime-type type="application/x-mytype">  
   <comment>A witty comment</comment>
   <comment xml:lang="it">Uno Commento</comment>
   <glob pattern="*.myapp"/>
  </mime-type>
 </mime-info>

Install the configuration file:

xdg-mime install mytype-mime.xml

This gets your files recognized and associated with an icon. xdg-mime default can be used for associating an application with the MIME type after you get a .desktop file installed.

skolima
jldupont

related questions