You are not logged in.

#1 2024-12-30 20:49:48

eggrole
Member
Registered: 2021-01-30
Posts: 13

[SOLVED] How to set correct mimetype for open-xdg?

I am trying to get drawio files to open with the correct application using
xdg-open. Currently the .drawio files are being recognized as text/plain and
opening in vim.

If I try `/usr/bin/drawio test.drawio` or `drawio test.drawio` it works as
expected.

I'm not sure where to go next. I am thinking there might be a way to force
the .drawio to behave as a application/vnd.jgraph.mxfile?

Below are what I think are the relevant outputs.


$ xdg-mime query filetype test.drawio
text/plain
$ file --mime-type test.drawio
test.drawio: text/plain
$ file --mime-encoding test.drawio
test.drawio: us-ascii
$ file --mime test.drawio
test.drawio: text/plain; charset=us-ascii
$ cat /usr/share/applications/drawio.desktop

[Desktop Entry]
Name=drawio
Comment=A diagramming and whiteboarding desktop app
Exec=/usr/bin/drawio %U
Terminal=false
Type=Application
Icon=drawio
StartupWMClass=drawio
Categories=Graphics;
MimeType=application/vnd.jgraph.mxfile;application/vnd.ms-visio.drawing.main+xml;
$ cat /usr/share/mime/packages/drawio.xml

<?xml version="1.0" encoding="utf-8"?>
<mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
<mime-type type="application/vnd.jgraph.mxfile">
  <glob pattern="*.drawio"/>
    <comment>draw.io Diagram</comment>
  <icon name="x-office-document" />
</mime-type>
</mime-info>
$ cat /usr/share/mime/application/vnd.jgraph.mxfile.xml

<?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="application/vnd.jgraph.mxfile">
  <!--Created automatically by update-mime-database. DO NOT EDIT!-->
  <glob pattern="*.drawio"/>
  <comment>draw.io Diagram</comment>
  <icon name="x-office-document"/>
</mime-type>
$ grep drawio /etc/mime.types

application/vnd.jgraph.mxfile     drawio
application/vnd.ms-visio.drawing.main+xml drawio

I don't think this should be relevant, but for completeness:

$ cat /usr/share/mime/application/vnd.ms-visio.drawing.main+xml.xml

<?xml version="1.0" encoding="utf-8"?>
<mime-type xmlns="http://www.freedesktop.org/standards/shared-mime-info" type="application/vnd.ms-visio.drawing.main+xml">
  <!--Created automatically by update-mime-database. DO NOT EDIT!-->
  <comment>Office Open XML Visio drawing</comment>
  <comment xml:lang="en_GB">Office Open XML Visio drawing</comment>
  --- removed other lang comments for brevity in post ---
  <generic-icon name="image-x-generic"/>
  <glob pattern="*.vsdx"/>
  <sub-class-of type="application/zip"/>
</mime-type>

I tried renaming test.drawio to test.vsdx and it still opened as text in vim.

Last edited by eggrole (2024-12-31 21:27:18)

Offline

#2 2024-12-31 09:31:43

seth
Member
Registered: 2012-09-03
Posts: 60,776

Re: [SOLVED] How to set correct mimetype for open-xdg?

Did you run update-mime-database ?
https://wiki.archlinux.org/title/XDG_MI … MIME_types

Offline

#3 2024-12-31 20:18:20

eggrole
Member
Registered: 2021-01-30
Posts: 13

Re: [SOLVED] How to set correct mimetype for open-xdg?

seth wrote:

I did.

During my search I found others having the same issue (with drawio). The solutions (for Debian based) were to create all of the stuff I listed. Some of it was there, but not all. I for sure had to add the entries in `/etc/mime.types` and then run the update-mime-database. I actually ran it several times, targetting /usr/share/mime. I also tried rebooting.

After looking into more last night I also found:

$ gio info test.drawio | grep standard
  standard::type: 1
  standard::is-hidden: FALSE
  standard::is-backup: FALSE
  standard::is-symlink: FALSE
  standard::name: test.drawio
  standard::display-name: test.drawio
  standard::edit-name: test.drawio
  standard::copy-name: test.drawio
  standard::icon: x-office-document, application-vnd.jgraph.mxfile, application-x-generic, x-office-document-symbolic, application-vnd.jgraph.mxfile-symbolic, application-x-generic-symbolic
  standard::content-type: application/vnd.jgraph.mxfile
  standard::fast-content-type: application/vnd.jgraph.mxfile
  standard::size: 7220
  standard::allocated-size: 8192
  standard::symbolic-icon: x-office-document-symbolic, application-vnd.jgraph.mxfile-symbolic, application-x-generic-symbolic, x-office-document, application-vnd.jgraph.mxfile, application-x-generic

which looks like everything is pointing correctly.

I also learned that mimetypes are not actual metadata in the files and "assumed" through the extension. So I can't assign a mimetype to a file per se. I am guessing this is where the globbing for *.drawio comes in.

Last edited by eggrole (2024-12-31 20:22:38)

Offline

#4 2024-12-31 21:00:15

seth
Member
Registered: 2012-09-03
Posts: 60,776

Re: [SOLVED] How to set correct mimetype for open-xdg?

I also learned that mimetypes are not actual metadata in the files and "assumed" through the extension.

Yes, "file" runs a heuristic on the signature (first bytes) of a file to check what that probably is. It cannot tell apart one xml file from another.

You're probably running in the generic resolution then?

bash -x /usr/bin/xdg-mime query filetype test.drawio |& grep generic

It'll prefer the mimetype binary from perl-file-mimeinfo, but that's an optional dependency only and /usr/bin/vendor_perl/ is possibly not even in your $PATH?
"gio info" is only used on gnome (even if you have it installed, the xdg scripts suck big time)

Offline

#5 2024-12-31 21:19:32

eggrole
Member
Registered: 2021-01-30
Posts: 13

Re: [SOLVED] How to set correct mimetype for open-xdg?

$ bash -x /usr/bin/xdg-mime query filetype test.drawio |& grep generic
+ DE=generic
+ info_generic /home/egg/test.drawio

I'm not sure what this is saying. I don't use a desktop environment (DE?). I use only openbox.

It looks like /usr/bin/vendor_perl/ is in my $PATH:

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/opt/rocm/bin:/usr/lib/rustup/bin:/home/egg/.local/bin/:/home/egg/thinkorswim/:/home/egg/.scripts/ <and some scripts sub dirs>

It seems like I do NOT have perl-file-mimeinfo.

Last edited by eggrole (2024-12-31 21:24:34)

Offline

#6 2024-12-31 21:23:50

seth
Member
Registered: 2012-09-03
Posts: 60,776

Re: [SOLVED] How to set correct mimetype for open-xdg?

I'm not sure what this is saying

You're using the generic resolution and probably indeed "file".

pacman -S perl-file-mimeinfo

then try again.

Offline

#7 2024-12-31 21:26:58

eggrole
Member
Registered: 2021-01-30
Posts: 13

Re: [SOLVED] How to set correct mimetype for open-xdg?

You beat my edit. I didn't have perl-file-mimeinfo installed.

Installing it worked!

Thank you so much for your help today and the other times I've posted. I very much appreciate your knowledge and time. Have a great New Year!

Offline

#8 2024-12-31 21:38:39

eggrole
Member
Registered: 2021-01-30
Posts: 13

Re: [SOLVED] How to set correct mimetype for open-xdg?

For anyone interested, I learned a little more about the generic resolution and how xdg-open defaults to "file" when there is no desktop environment at https://unix.stackexchange.com/question … xt-formats

Not only did seth fix my issue, he led me to learn a little bit more of how all this linux stuff works. Double thank you.

Offline

Board footer

Powered by FluxBB