Syntax coloring

sábado, 25 de abril de 2009

Making firefox open files honoring KDE's file associations

A very frustrating issue for KDE users with firefox are the file associations. And manually setting the program for each file type is just too tedious.

What we have to do is provide a $HOME/.mailcap file which associates all file types with the xdg-open script, which will honor the file associations set in KDE (and other DE's too). Firefox uses that file to read the associations. If you want this to be system-wide (all users), copy it over /etc/mailcap (as root - backup is always a good idea) .

The easier way is to run the following command:
wget http://luisfpg.uuuq.com/blog/mailcap -O ~/.mailcap

This script was generated with update-user-mailcap, a ruby script that reads /etc/mime.types and generates the $HOME/.mailcap file. To run it, execute the following commands:
wget http://luisfpg.uuuq.com/blog/update-user-mailcap
chmod +x
update-user-mailcap
./update-user-mailcap

If you don't trust me, examine the file first. It's always a good idea to do this when downloading scripts from the Internet, by the way.

Attention:
If you had previously customized some file associations in firefox, you might want to rename the $HOME/.mozilla/firefox/profile/mimeTypes.rdf to other name (or just remove it) and restart firefox to have the associations reset.

A (minor) drawback is that on the file download dialog, you will always see xdg-open as the program, and not the real program which will be used to open the file, but it will work. Trust me ;)

11 comentários:

MatonisK disse...

For some reasons, xdg-open *from within firefox*, uses xfce4 file associations. When i invoke xdg-open from shell, it uses kde associations.

I downloaded your mailcap file, didn't changed anything.

Luis Planella disse...

Actually, I only have KDE installed.
Probably xdg-open reads something in your environment, making XFCE (probably GTK) having precedence...
In Konsole, the environment points to KDE.
Just a guess...

Schultz! disse...

Why the hell do you need a huge ruby program for that? You ruby guys crack me up.

for i in $(cat /etc/mime.types | awk '{print $1}' | grep ^[^#]); do echo "$i; xdg-open '%s';" >> mailcap; done

Luis Planella disse...

Actually, I'm a Java programmer.
I'm not keen in bash / awk, so the closest thing was ruby.
Anyway, I've made the final .mailcap downloadable...
Thanks for your tip.

Christian disse...

hey works great for hyperlinks, but does not work for the "downloads" window. Any idea how to make Firefox opening the already downloaded files with the mime-registerd apps?
regards, Christian

Luis Planella disse...

This is strange, as it works for me with the downloads window as well...
Maybe the file no longer exists on disk? If so, firefox does nothing when double clicking the file, and the right click context menu has the open option disabled...

Christian disse...

Oi Luis, thank you for your answer. The file still exists on the disk. Double-clicking on the item in the downloads-window makes Firefox opening the choose-the-application-window. Same for right-click and "open" in the menue and for "show enclosing folder".

Andy disse...

Hi, I had the same issue.
The solution was good with xdg-open, but I had to delete the (obsolete) file "/usr/share/applications/mimetypes.info"

Thank you for the solution via xdg-open and for the useful script.

bYe,
Andy

Denis disse...

Another thing - if it didn't helped with applications like gimp for PDF files - try to rename the file /usr/share/applications/mimeinfo.cache - after that it will surely use xdg )

johnny_boy disse...

This didn't work for me, but I'm not surprised since I'm running KDE 4.10 (RC3) on Kubuntu 12.10 and FF 18. Something's been changed somewhere.

Alex Gold disse...

Its good to be here, very nice post, the content is amazing, keep posting friend it will be very helpful for everyone, Thanks for sharing. I really liked it.
visit this website Mozilla Firefox Support and Call +1-800-231-4635 USA (Toll Free).