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 underst开发者_JAVA技巧and it to be an identifier to my application but how do I define it?
xdg-mime default xxx.desktop text/mfe
All the needed information is in man xdg-mime
.
Check the actual mime-type with
xdg-mime query filetype filename.ext
(the response could be e.g.application/octet-stream
)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
.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.At this point, if you check again the mime-type (like in step 1.) you should have the desired response (your new mime-type).
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).The last step is registering the icon with
xdg-icon-resource
but that's another topic.
Hope this helps!
To be able to xdg-open afile.myapp
:
- make a description xml for the file type, like you did.
- run
xdg-mime install vendor-filetype.xml
- make a
myapp.desktop
file for your application, like this: .desktop example - run
xdg-mime default myapp.desktop filetype
Adding a applied case, for composed filenames, since xdg-mime default
was not working for me in this particular case.
The goal: associate all files *.mybot.json
with a special dedicated script mybot
, while retaining the default behavior of a regular .json
file (Eq: dropping in Firefox will still recognize the files as .json
, but clicking them will open the pre defined mybot
script)
✅ Create mybot.xml
:
<?xml version="1.0"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/mybot">
<comment>My Bot json data</comment>
<glob pattern="*.mybot.json"/>
</mime-type>
</mime-info>
✅ Create mybot.desktop
, and test it:
Clicking it should launch the script called mybot
in /home/bots/
.
ⓘ The target script mybot
must be set executable and be a hashbang shell script, with the lang interpreter set on the first line, because launched by bash.
ⓘ We can use one of the numerous icon existing in /usr/share/icons
.
[Desktop Entry]
Version=1.0
Name=mybot
Exec=bash -c '/home/bots/mybot;/bin/bash'
Icon=utilities-terminal
Terminal=true
Type=Application
Categories=Development;
⚠️ It is important to click it one time and mark it as trusted. The icon will change after that.
✅ Mime install on the machine, files explorer will then start to recognize *.mybot.json
files as My Bot json data (application/mybot)
.
sudo xdg-mime install mybot.xml
✅ Then, simply copy the .desktop launcher in /usr/share/applications
:
sudo cp mybot.desktop /usr/share/applications
精彩评论