Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Register file extensions / mime types in Linux

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 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.

like image 576
amarillion Avatar asked Aug 27 '08 19:08

amarillion


People also ask

What is MIME type in Linux?

MIME types are a sort of identification card for files on Ubuntu. A file's MIME type is usually determined by the extension of its filename; for example, a text file may end in . txt, and image file might end in . png or . jpg.

How do you specify the MIME type of a file?

3.2. Another way to get the MIME type of a file is by reading its content. We can determine the MIME type according to specific characteristics of the file content. For example, a JPG starts with the hex signature FF D8 and ends with FF D9. This is slower than the file extension approach due to the extra I/O efforts.

What is the extension of MIME file?

MIME files are more commonly seen using a . MIM extension.

Where is MIME type stored in a file?

All MIME type information is stored in a database. The MIME database is located in the directory /usr/share/mime/ . The MIME database contains a large number of common MIME types, stored in the file /usr/share/mime/packages/freedesktop.


1 Answers

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'>   <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.

like image 180
skolima Avatar answered Sep 20 '22 13:09

skolima