How Do I Create Mime Types For New Documents (Command Line)?
How do I give my application's custom document a custom icon? Additionally, how do I make the file manager open these documents when a user double clicks on them?
I have to do this on the command line because the solution will be used inside an installation script.
The correct solution can be found --> here <-- , but a foo
version is provided below to directly answer the question.
Please pay very close attention to the use of application-x-foo
, x-foo
, and foo
as they change throughout.
Note: When updating the Ubuntu tutorial, it's probably better in an example to distinguish between the foo
application, foo
the extension and foo
mimetype to avoid confusion moving forward. i.e. lmms
uses *.mmpz
and x-lmms-project
, which helped a lot in figuring this out.
wget http://soqr.fr/testsvg/zebra.svg -O ~/Desktop/application-x-foo.svg
<?xml version="1.0" encoding="UTF-8"?>
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
<mime-type type="application/x-foo">
<comment>Foo File</comment>
<glob pattern="*.foo"/>
</mime-type>
</mime-info>
~/Desktop/x-foo.xml
[Desktop Entry]
Version=1.0.0
Encoding=UTF-8
Name=FooGazi
GenericName=Foo Application
Comment=This is my Foo Application
Exec=/usr/bin/foo
# Please change, system-shutdown.svg used only as example
Icon=/usr/share/icons/Humanity/actions/48/system-shutdown.svg
StartupNotify=true
Type=Application
MimeType=application/x-foo;
~/Desktop/foo.desktop
sudo xdg-mime install --mode system ~/Desktop/x-foo.xml
sudo cp ~/Desktop/foo.desktop /usr/share/applications
sudo cp ~/Desktop/application-x-foo.svg /usr/share/icons/gnome/scalable/mimetypes/
sudo xdg-mime default foo.desktop application/x-foo
sudo update-mime-database /usr/share/mime
sudo gtk-update-icon-cache /usr/share/icons/gnome/ -f
/etc/mime.types
but please confirm whether or not this is still needed and edit this post to reflect that.
Never, ever, edit existing files in /etc from you install script! That is a terribly bad idea. besides you don't need to edit /etc/mime.types
your xml file is still wrong, and in the wrong location it should be /usr/share/mime/text/x-foo.xml
<?xml version="1.0" encoding="UTF-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="text/x-foo">
<comment>Example file type </comment>
<glob pattern="*.foo"/>
</mime-type>
3rd party Icons are normally installed to: /usr/share/icons/hicolor/scalable/mimetypes