8 August 2008
Get Firefox To Honor KDE File Associations
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.

19 Comments
Ebrahim
3 November 2008
Great trick! Thanks :)
Frederik
27 November 2008
how about using xdg-open? it should always open with the right app, even when switching between kde and gnome
TerminalDigit
28 November 2008
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!
Stuart
20 December 2008
Any chance you can get this to work with Thunderbird?
TerminalDigit
20 December 2008
Stuart: Did you try it with Thunderbird?
Stuart
20 December 2008
Yes – but to no avail. Tried making the script in the /usr/bin section also but no change
Stuart
20 December 2008
Launched from the console – I see this error: Syntax Error: Too many arguments
TerminalDigit
21 December 2008
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?
Stuart
21 December 2008
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.
TerminalDigit
21 December 2008
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.
Stuart
21 December 2008
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???
TerminalDigit
22 December 2008
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.Stuart
22 December 2008
The script works fine from the cli – I guess I’m stuck for now. Thanks for all your help anyway!
Chiron613
19 January 2009
This was a great trick. I find it to be very useful.
Thanks.
TerminalDigit
19 January 2009
Glad it worked out for you Chiron613. :)
lowkey
25 January 2009
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!
luisfpg
26 April 2009
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.
TerminalDigit
26 April 2009
Thanks luis! Many ways to get this done, it seems.
tommcdo
27 August 2009
I know this is an old thread, but I want to point out that lowkey is right — “$1″ is required if the files have spaces. Firefox may do its own escaping or quoting, but that only works far enough for the script being called to correctly identify the first argument. Once you put $1 in your script, it doesn’t care anymore that the invoker intended that as a single argument; now it looks like some more arguments separated by spaces.
Verify this to yourself using the following 2 scripts:
script1.sh:
#!/bin/bash
./script2.sh $1
script2.sh:
#!/bin/bash
echo $1
Now call script1.sh as such:
./script1.sh “foo bar”
(or ./script1.sh foo\ bar)
You will see tha tit only prints foo. However, if script1.sh is modified to use “$1″, it will print “foo bar”.