Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the xdg-mime command

Tags:

Can someone provide example on how to use (with GNOME Ubuntu) the XDG-MIME command? I'm struggling to get anything working even with the docs.

For example if I want to register the extension .mfe with an application called MyApp what would the steps be? This is my attempt so far, I would appreciate any pointers on getting this right...

This is my xml (MyApp-MyFileType.xml) How is the file name relavent?

<?xml version="1.0"?> <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>   <mime-type type="text/mfe">     <comment>File for MyApp</comment>     <glob pattern="*.mfe"/>   </mime-type> </mime-info> 

Then is run this command?

xdg-mime install MyApp-MyFileType.xml 

And then I run this? What does the xxx relate to?, I understand it to be an identifier to my application but how do I define it?

xdg-mime default xxx.desktop text/mfe 
like image 993
Superted Avatar asked Jan 13 '10 21:01

Superted


People also ask

How does xdg open work?

xdg-open opens a file or URL in the user's preferred application. If a URL is provided the URL will be opened in the user's preferred web browser. If a file is provided the file will be opened in the preferred application for files of that type. xdg-open supports file, ftp, http and https URLs.

What are xdg-utils?

xdg-utils is a set of tools that allows applications to easily integrate with the desktop environment of the user, regardless of the specific desktop environment that the user runs.

What is mime type of a file?

A media type (also known as a Multipurpose Internet Mail Extensions or MIME type) indicates the nature and format of a document, file, or assortment of bytes. MIME types are defined and standardized in IETF's RFC 6838.

Where is Mimeapps list?

The /usr/share/applications/mimeapps. list and /usr/share/applications/gnome-mimeapps. list files specify which application is registered to open specific MIME types by default. These files are provided by the distribution.


2 Answers

All the needed information is in man xdg-mime.

  1. Check the actual mime-type with xdg-mime query filetype filename.ext (the response could be e.g. application/octet-stream)

  2. If you decide to create your own mime-type you should edit an XML file like the example you gave. You should check if the mime-type name you want to create exists to not override it. You can see the registered mime-types in /usr/share/applications/defaults.list.

  3. Then, as you pointed out, it's time to register the new mime-type with sudo xdg-mime install --mode system MyApp-MyFileType.xml to install for all users on the system.

  4. At this point, if you check again the mime-type (like in step 1.) you should have the desired response (your new mime-type).

  5. Now it's time to register the new mime-type with the desired application. The association is done with sudo xdg-mime default MyApp.desktop text/mfe (in your example). To see the available .desktop files just do: ls /usr/share/applications | less (I think this is what you were looking for).

  6. The last step is registering the icon with xdg-icon-resource but that's another topic.

Hope this helps!

like image 187
15 revs, 5 users 63% Avatar answered Dec 27 '22 11:12

15 revs, 5 users 63%


To be able to xdg-open afile.myapp:

  1. make a description xml for the file type, like you did.
  2. run xdg-mime install vendor-filetype.xml
  3. make a myapp.desktop file for your application, like this: .desktop example
  4. run xdg-mime default myapp.desktop filetype
like image 33
Eelvex Avatar answered Dec 27 '22 12:12

Eelvex