You are not logged in.

#1 2010-09-13 23:18:05

ConnorBehan
Package Maintainer (PM)
From: Long Island NY
Registered: 2007-07-05
Posts: 1,359
Website

Howto: turn off pesky MIME type handling enforced by some programs

I finally did something about this on my system. You know how file managers like Thunar and Nautilus give multiple MIME types to the same file? Openoffice text will be treated as an openoffice document as well as a compressed tar for instance. There could also be multiple programs capable of viewing a file that has one MIME type. e.g. GIMP becomes the default "image viewer" even though you have a lightweight program that you'd rather use instead.

Of course none of this is a pain if you use the command line but for the times when I click on files in Thunar, I don't want to have to always worry about whether I should've right clicked and gone "open with." Anyway, here's how I deleted ALL the default MIME handlers and re-instated my own.

#!/bin/bash

# The pieces inside ### should be in your cron or pacman wrapper if you want this to stay

###
cd /usr/share/applications
ls | grep desktop | xargs sed -i -e '/MimeType=/d'
ls | grep desktop | xargs sed -i -e 's/StartupNotify=true/StartupNotify=false/g'
###

for file in `ls | grep desktop`; do
    cp $file ~/.local/share/applications/${file/.desktop/-usercreated.desktop}
done

rm ~/.local/share/applications/mimeinfo.cache
rm ~/.local/share/applications/defaults.list

Then I recreated defaults.list as (not exhaustive but still growing):

[Default Applications]
audio/x-wav=audacity-usercreated.desktop
application/x-shockwave-flash=swfdec-player-usercreated.desktop
application/x-java-jnlp-file=java-web-start-usercreated.desktop
audio/mpeg=audacity-usercreated.desktop
application/x-bittorrent=deluge-usercreated.desktop
application/javascript=medit-usercreated.desktop
application/rdf+xml=medit-usercreated.desktop
application/zip=xarchiver-usercreated.desktop;squeeze-usercreated.desktop
application/x-compressed-tar=xarchiver-usercreated.desktop;squeeze-usercreated.desktop
video/mp4=mplayer-usercreated.desktop
text/html=medit-usercreated.desktop;chromium-usercreated.desktop;firefox-usercreated.desktop
application/postscript=evince-usercreated.desktop
application/x-cbr=evince-usercreated.desktop
text/plain=medit-usercreated.desktop
video/x-msvideo=mplayer-usercreated.desktop
application/x-cbz=evince-usercreated.desktop
image/gif=mirage-usercreated.desktop;gimp-usercreated.desktop
audio/x-flac=audacity-usercreated.desktop
application/vnd.ms-powerpoint=impress-usercreated.desktop
application/x-java-archive=xarchiver-usercreated.desktop;squeeze-usercreated.desktop
application/smil=kino-usercreated.desktop
application/vnd.oasis.opendocument.text=writer-usercreated.desktop
video/x-flv=mplayer-usercreated.desktop
application/vnd.oasis.opendocument.spreadsheet=calc-usercreated.desktop
application/x-gnumeric=gnumeric-usercreated.desktop
image/png=mirage-usercreated.desktop;gimp-usercreated.desktop
application/x-audacity-project=audacity-usercreated.desktop
video/x-ms-wmv=mplayer-usercreated.desktop
image/jpeg=mirage-usercreated.desktop;gimp-usercreated.desktop
application/msword=writer-usercreated.desktop;abiword-usercreated.desktop
image/bmp=mirage-usercreated.desktop;gimp-usercreated.desktop
video/mpeg=mplayer-usercreated.desktop
application/pdf=epdfview-usercreated.desktop;evince-usercreated.desktop
application/vnd.oasis.opendocument.presentation=impress-usercreated.desktop

I know that's out of order, but if I put it in order, it gets screwed up again the next time Thunar edits it.

I found out the mime type names in the first place by clicking on a file I wanted to open and typing in the custom command /usr/bin/dummy.  /usr/bin/dummy is a script I made which simply deletes the newly created dummy-usercreated.desktop file. Then I just go into defaults.list and change the appended

foo/x-bar:dummy-usercreated.desktop

to

foo/x-bar:whatever-i-want-usercreated.desktop

And yes the "-usercreated" suffix does seem to be special. The next step would be converting firefox to use this I think.

One other thing I did was delete /root/.local/share/applications and I made a smylink /root/.local/share/applications -> ~/.local/share/applications so root file managers get the benefit for free. Of course then you must be careful to run:

#!/bin/bash

cd ~/.local/share/applications
ls | grep desktop | xargs sed -i -r 's/Exec=(.*)/Exec=sudo -u your_user \1/g'

Last edited by ConnorBehan (2010-09-13 23:22:41)


6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.

Offline

#2 2010-12-02 05:36:13

ConnorBehan
Package Maintainer (PM)
From: Long Island NY
Registered: 2007-07-05
Posts: 1,359
Website

Re: Howto: turn off pesky MIME type handling enforced by some programs

First caveat noticed:

I had to recompile thunar-archive-plugin and hardcode it to use xarchiver. Before the only way for it to discover xarchiver was to use the mime database which I deleted in the OP. I don't know how to reimplement this plugin as a Thunar action because the Thunar vfs doesn't have an easy way to distinguish archive types.


6EA3 F3F3 B908 2632 A9CB E931 D53A 0445 B47A 0DAB
Great things come in tar.xz packages.

Offline

Board footer

Powered by FluxBB