LWN.net Logo

Debian associations

Debian associations

Posted Jun 2, 2010 23:47 UTC (Wed) by drag (subscriber, #31333)
In reply to: Debian associations by kmself
Parent article: Giggle: A Git GUI

GNOME, KDE, and XFCE4 each have their standard application associations which are more or (usually) less coordinated. Manage through their respective configuration utilities (gconf-editor, gconftool, gconftool-2 for GNOME, if you want to avoid the GUI configurator, not sure that KDE or XFCE4 have similar tools).

No... Not really. Not at least for well-written applications. There are tons of applications that do not follow the standards setup for handling file associations, but there are standards and they do not involve anything to do with gconf or anything like that.

In Gnome and KDE the file type association should be handled the same. I don't know about KDE 3.x stuff, but KDE 4.x should work sanely.

They all use the .desktop FreeDesktop.org standard.

The idea is that every typical desktop-oriented application should have a *.desktop file associated with it that gets installed to your system. This file describe what icon to use for it, internationalization names, short names, comments, how to launch he application, and that sort of thing.

example:

$ locate gedit.desktop
/usr/share/app-install/desktop/gedit.desktop
/usr/share/applications/gedit.desktop
/var/lib/menu-xdg/applications/menu-xdg/X-Debian-Applications-Editors-gedit.desktop


That way your desktop environment can educate itself and use automatically generated menus so that you don't have to hard code menus and file associations like you did in the bad old days.

------------------

Some examples on how to use it.

FOR LAUNCHING APPLICATIONS AT LOGIN:

To launch a application at start up make a symbolic link, copy the *.desktop file, or create your own *.desktop file and stick it into "$HOME/.config/autostart"

You can specify in there if you only want it to be launched from a particular desktop environment, or you can eliminate that and then all compliant desktop session managers should launch it at log in.

You can easily create your own .desktop file and store it at "$HOME/.local/share/applications"

MANAGING FILE TYPE ASSOCIATIONS:

File associations are managed by 'defaults.list' file. This file lists the mime type and then the corresponding *.desktop file for the application you want to be used by default.

This file is can be manually created and managed, or it will be created by your desktop environment (usually your file manager) when you change the defaults. You can edit it directly and will be honored right away.

Gnome and KDE (and probably other desktop environments) will have their own set of default lists. On my system (Debian) the Gnome list is located at "/usr/share/gnome/applications/defaults.list"

Your own settings will override the generic defaults and that file can be found at: "$HOME/.local/share/applications/defaults.list"

HOW TO DEAL WITH STUPID APPLICATIONS/APP AUTHORS:

These are applications that launch other applications to handle media whose authors don't have a clue about the freedesktop.org stuff, or are legacy applications.

Most of these applications you have to manually set their own application-specific configuration for launching external apps. (like you really want to spend your time configuring each and every application you use to use every other application you want to use)

To easily deal with them you just tell them to use the '/usr/bin/xdg-open' (or gnome-open) application. These are standardized tools designed to be used by scripts and application authors to make it possible to conform to the standards with minimal effort.

One example application I use that I need to do this with is Liferea. I use it for a variety of feeds, some of which are podcasts and some are video feeds. I just go through and use 'xdg-open' for every thing.

Similar problems exist for the users of Firefox and other non-Gnome/non-KDE applications. Also this is very common problem for GTK-using, but otherwise non-Gnome applications.

For applications like 'mutt' that want the spawned process to block until your finished with it then you'll have to go to greater lengths.

This python script will launch applications similar to xdg-open or gnome-open, but will block until you close out the child app.
#! /usr/bin/env python

import gnomevfs
import os
import sys

# taken from http://therning.org/magnus/archives/251

mime_type = gnomevfs.get_mime_type(sys.argv[1])
mime_app = gnomevfs.mime_get_default_application(mime_type)
application = os.popen('whereis %s' % mime_app[2]).readline().split(' ')[1]

os.execl(application, application, sys.argv[1])
I call it 'mutt-helper.py' and my $HOME/.mailcap file looks like this:
application/*; $HOME/bin/mutt-helper.py '%s'; test=test -n '$DISPLAY'
image/*; $HOME/bin/mutt-helper.py '%s'; test=test -n '$DISPLAY'
audio/*; $HOME/bin/mutt-helper.py '%s'; test=test -n '$DISPLAY'
multipart/*; $HOME/bin/mutt-helper.py '%s'; test=test -n '$DISPLAY'
video/*; $HOME/bin/mutt-helper.py '%s'; test=test -n '$DISPLAY'
text/*; $HOME/bin/mutt-helper.py '%s'; test=test -n '$DISPLAY'


(Log in to post comments)

Debian associations

Posted Jun 3, 2010 7:12 UTC (Thu) by rvfh (subscriber, #31018) [Link]

You could have contributed this as an article to LWN! Very informative, thank you.

Debian associations

Posted Jun 8, 2010 20:31 UTC (Tue) by nix (subscriber, #2304) [Link]

It is frankly insane that this is even necessary. It seems like 'block until complete' should be built into xdg-open.

Debian associations

Posted Jun 6, 2010 23:02 UTC (Sun) by mikov (subscriber, #33179) [Link]

I think you are forgetting additional settings like x-www-browser, 'gconftool-2 /desktop/gnome/url-handlers/http/command', and who knows what else...

Plus, on my system there are four separate defaults.list with conflicting settings:

/etc/gnome-vfs-2.0/defaults.list
/home/$HOME/.local/share/applications/defaults.list
/usr/local/share/applications/defaults.list
/usr/share/gnome/applications/defaults.list

I use KDE 3.5. Do they all apply? Which one takes precedence? I am sure I could find out, but who has time for such nonsense...

Seriously, this is a sad state of affairs.

Debian associations

Posted Jun 7, 2010 8:32 UTC (Mon) by ikm (subscriber, #493) [Link]

> I am sure I could find out, but who has time for such nonsense...

Yep, that's exactly why I just try not to use associations at all. It's not really handy, but it seems simpler than trying to figure out how to fix them.

Re: Debian associations

Posted Jun 10, 2010 4:30 UTC (Thu) by ldo (subscriber, #40946) [Link]

Ummm .. I notice you have single quotes instead of double ones in '$DISPLAY'. Does that do what you intend?

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds