Get Firefox To Honor KDE File Associations
8 August 2008 | 19 Comments
Firefox is a nice browser, but it’s very Gnome-centric. In a KDE environment, it’s totally clueless about what application to use to open any downloaded file. Here’s a little fix I came up with (although probably many others have thought of this) that associates all files with a kfmclient script which is smart enough to do the right thing.
Update (1 Feb 2009): I’ve incorporated suggestions from several commenters (thanks!):
- At the konsole, type:
which xdg-openand note the output. On my machine it’s/usr/bin/xdg-open. - Show Firefox who’s boss by double-clicking a file in the Downloads list, enter the location of xdg-open into the textbox (or browse to it), and check the option to remember the association for all files.
- Done! Live your life! Be nice to others.
If for some reason this doesn’t work for you, you might try the instructions from the original version of this post:
- Make the script:
mkdir -p ~/bin
echo -e '#!/bin/bash\nkfmclient exec $1' > ~/bin/kdeff.sh
chmod +x ~/bin/kdeff.sh- Show Firefox who’s boss by double-clicking a file in the Downloads list, choosing to open that file with the script we just created, and checking the box to remember the association for all files.
- You’re done. Notice the “Open Containing Folder” option also works now. You’re welcome.
![]()
Editorial note: Another solution to this problem is to use Opera, which in my experience, does the right thing on every platform. This has the added benefit of entirely bypassing the extension-hunt-wait-grind-your-teeth-dance that happens with every new version of Firefox. Every extension I have for Firefox duplicates functionality that is built into Opera by default, with the exception of NoScript for which I haven’t found an Opera match, although they’re getting very close.

Great trick! Thanks
how about using xdg-open? it should always open with the right app, even when switching between kde and gnome
Hi Frederik,
You’re absolutely right, xdg-open would work as well. It also has the additional benefit you mentioned, although personally I’d never switch to Gnome.
Thanks for the tip!
Any chance you can get this to work with Thunderbird?
Stuart: Did you try it with Thunderbird?
Yes – but to no avail. Tried making the script in the /usr/bin section also but no change
Launched from the console – I see this error: Syntax Error: Too many arguments
Stuart: What exactly are you trying to do? I assumed you wanted to open attachments from Thunderbird without getting prompted. The method described in the post works perfectly for me for that purpose. Are you trying to do something different?
When I try to open an attached file using tbird (linux) I get the “Browse” option but no applications and browse links to my home directory, not any applications. I was hopeful your script would work, but it does not as I noted above. I followed your instructions and created the “kdeff.sh” script, browsed to it when trying to open a file, and nothing happens. When I launch tbird from the cli rather than gui, I get the “Too many arguments” error.
Stuart: I’ve done exactly the same thing: Select an attachment, click browse, drill down to kdeff.sh and select it, and it works here. A few questions:
1. Did you make the script executable?
2. Does this work for you in Firefox?
3. Post your kdeff.sh here so I can verify you’ve created it correctly.
1. Yes
2, Didn’t really have this issue with firefox. I guess I don’t really execute from downloads as much as I want to from attachments.
3. Here’s my ~/.bin/kdeff.sh
#!/bin/bash
kfmclient exec $1
I get the “Too many…” error. Maybe there is some other problem with my install???
Yeah, everything looks good. I’m not sure why it isn’t working for you. Try launching any old file using the script from the console. Maybe something like
user@host$: ~/.bin/kdeff.sh ~/this_is_some_random_text_file.txtwill give more useful output. Or maybe use xdg-open instead like Frederik suggested.The script works fine from the cli – I guess I’m stuck for now. Thanks for all your help anyway!
This was a great trick. I find it to be very useful.
Thanks.
Glad it worked out for you Chiron613.
You might want to put quotes around the $1 so that it can handle filenames with spaces in them.
Other than that it worked perfectly for me.
Thanks!
lowkey: Thanks for your comment, but I’m pretty sure that’s not true.
I think you’re misunderstanding the flow here. The $1 goes into a shell script, and refers to the first parameter Firefox passes to it. Firefox (as it should) escapes all spaces in the path, so there is only one parameter passed to the script.
Even if this weren’t true and Firefox was not escaping the path correctly, quoting the variable “$1″ still would only refer to the first argument. In this case, we’d probably need to replace it with something like
\"$@\".Hope that was helpful.
You might also check my post at http://luisfpg.blogspot.com/2009/04/making-firefox-open-files-honoring-kdes.html
It resolves the same problem by creating a $HOME/.mailcap file, from which firefox reads the default file associations.
Thanks luis! Many ways to get this done, it seems.