#StackBounty: #shell #mime-types "xdg-mime query filetype" returning different filetype than "file –mime-type"

Bounty: 50

I have a bash script that runs to create emails. I do not wish to modify it for now since it is pretty critical in my current project. One command does not run the same on the operational machine and on mine:

xdg-mime query filetype <file>

It’s running on a simple us-ascii encoded text file (with a custome file extension). The thing is, on the operational machine where the script works, it returns plain/text (expected behavior). Debug mode of xdg-mime shows that it is actually running a file -i command on the operational machine. On my machine though, it returns application/octet-stream and runs a gnomevfs-info command. It appears to have something to do with the desktop environment (both machines are running on gnome).

Is there a way to force xdg-mime to run file -i? Or to make gnomevfs-info return the correct mime type ? I tried unsetting GNOME_DESKTOP_SESSION_ID but here is what xdg-mime does:

    if [ x"$KDE_FULL_SESSION" = x"true" ]; then DE=kde;
    elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then DE=gnome;
    elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1` ; then DE=gnome;
    elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = "xfce4"$' >/dev/null 2>&1; then DE=xfce;

The third elif is the one that leads to xdg-mime using gnomevfs-info over file -i, because the command returns 0 and DE is set to gnome. I’ve tried looking at man pages, but that command dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager > /dev/null 2>&1 is jibberish to me.

Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.