Posted Jun 2, 2010 23:47 UTC (Wed) by drag
In reply to: Debian associations
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.
$ locate 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
# taken from http://therning.org/magnus/archives/251
mime_type = gnomevfs.get_mime_type(sys.argv)
mime_app = gnomevfs.mime_get_default_application(mime_type)
application = os.popen('whereis %s' % mime_app).readline().split(' ')
os.execl(application, application, sys.argv)
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'
to post comments)