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!):

  1. At the konsole, type: which xdg-open and note the output. On my machine it’s /usr/bin/xdg-open.
  2. 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.
  3. 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:

  1. Make the script:
    mkdir -p ~/bin
    echo -e '#!/bin/bash\nkfmclient exec $1' > ~/bin/kdeff.sh
    chmod +x ~/bin/kdeff.sh
  2. 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.
  3. 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

  1. Ebrahim said on 3 Nov 2008 at 8:39 AM:

    Great trick! Thanks :)

  2. Frederik said on 27 Nov 2008 at 5:00 AM:

    how about using xdg-open? it should always open with the right app, even when switching between kde and gnome

  3. TerminalDigit said on 28 Nov 2008 at 12:54 AM:

    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!

  4. Stuart said on 20 Dec 2008 at 9:58 AM:

    Any chance you can get this to work with Thunderbird?

  5. TerminalDigit said on 20 Dec 2008 at 1:54 PM:

    Stuart: Did you try it with Thunderbird?

  6. Stuart said on 20 Dec 2008 at 4:20 PM:

    Yes – but to no avail. Tried making the script in the /usr/bin section also but no change

  7. Stuart said on 20 Dec 2008 at 4:21 PM:

    Launched from the console – I see this error: Syntax Error: Too many arguments

  8. TerminalDigit said on 21 Dec 2008 at 1:39 AM:

    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?

  9. Stuart said on 21 Dec 2008 at 8:47 AM:

    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.

  10. TerminalDigit said on 21 Dec 2008 at 11:22 AM:

    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.

  11. Stuart said on 21 Dec 2008 at 9:30 PM:

    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???

  12. TerminalDigit said on 22 Dec 2008 at 12:33 AM:

    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.txt will give more useful output. Or maybe use xdg-open instead like Frederik suggested.

  13. Stuart said on 22 Dec 2008 at 5:49 AM:

    The script works fine from the cli – I guess I’m stuck for now. Thanks for all your help anyway!

  14. Chiron613 said on 19 Jan 2009 at 7:46 PM:

    This was a great trick. I find it to be very useful.

    Thanks.

  15. TerminalDigit said on 19 Jan 2009 at 11:45 PM:

    Glad it worked out for you Chiron613. :)

  16. lowkey said on 25 Jan 2009 at 8:53 AM:

    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!

  17. TerminalDigit said on 1 Feb 2009 at 3:33 AM:

    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.

  18. luisfpg said on 26 Apr 2009 at 5:57 AM:

    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.

  19. TerminalDigit said on 26 Apr 2009 at 8:16 PM:

    Thanks luis! Many ways to get this done, it seems.

Leave a Reply