[conspire] exo-open(1), default handler, preferred application

Eric De Mund ead-conspire at ixian.com
Wed Mar 4 20:11:32 PST 2009


Rick,

Rick Moen <rick at linuxmafia.com> writes:
] Personally, I'm not at all happy with the idea of system software that
] decides what application software to run after I "click" on a file --
] which I realise is a key foundational requirement for all of the
] "desktop" suites (GNOME, KDE, Xfce). I want to know what's going to
] run, and be in control of that process, and in general don't have any
] use for "clicking" on data files at all. (The shell ain't broken.)

I hear you. As a control freak, I wasn't thrilled about it either. I
confess that when I saw GIMP starting up, handling my pdf file, I felt
violated, that a trust line had been crossed. This is a flavor of Unix,
after all. Why the h*ll were things happening that I hadn't set up?

But I've since regained control of exo-open(1)'s behavior; my 5:30am
understanding was flawed, incomplete. Here's a better explanation, for
CABALists, and for folks like me who might be Googling for a solution
to this.

0.  At package install/upgrade time, update-desktop-database(1) is
    called. (There's no manual page; view the source code at:
    <http://www.freedesktop.org/software/desktop-file-utils/releases/>.)

    update-desktop-database(1), part of the desktop-file-utils package,
    updates the MIME info cache (mimeinfo.cache file) stored in each
    directory of $XDG_DATA_DIRS/applications, from the "MimeType=" lines
    in all the .desktop files in those directories. (Cf.
    <http://standards.freedesktop.org/desktop-entry-spec/0.9.4/ar01s07.html>.)
    Note that if $XDG_DATA_DIRS is unset or null, it defaults to
    "/usr/local/share/:/usr/share/".

    These mimeinfo.cache files hold the mimetype<->desktop (application)
    mappings, they're human-readable text files, and edits to them take
    effect immediately.

    However, you can consider these files to be system files rather
    than personal, user files. And your personal mimeinfo.cache file
    and associated .desktop files in $XDG_DATA_HOME/applications (with
    $XDG_DATA_HOME defaulting to $HOME/.local/share if unset or null)
    take precedence and are consulted first. (Cf.
    <http://standards.freedesktop.org/basedir-spec/basedir-spec-0.5.html>.)

1.  exo-open(1) sends a message through the D-Bus message bus saying
    that it has a particular file to open that it needs to know the
    handler for. My read of the output of dbus-monitor(1) shows this
    message to either be a D-Bus "AddMatch" or "GetNameOwner" request.

2.  The result of this request, in the case of myresume.pdf, is
    "application/pdf". Some process as yet unknown to me consults
    $HOME/.local/share/applications/mimeinfo.cache, then, if necessary,
    continues on to e.g. /usr/share/applications/mimeinfo.cache, finds
    the line:

    application/pdf=evince.desktop;epdfview.desktop;gimp.desktop

    , and plucks off "evince.desktop".

    The file evince.desktop in that directory is consulted, and the 
    "Exec=" line is searched for.

3.  When "Exec=evince" is found, "evince" is plucked off and executed,
    with myresume.pdf as argument.

So, in a nutshell, to lock down your pdf launcher to one of your
choosing, create a $HOME/.local/share/applications/mimeinfo.cache file
containing e.g.

    [MIME Cache]
    application/pdf=evince.desktop

, copy e.g. evince.desktop from /usr/share/applications/ to
$HOME/.local/share/applications or make your own (here's a simple one
for xpdf(1):

    [Desktop Entry]
    Encoding=UTF-8
    Name=xpdf
    GenericName=PDF viewer
    Comment=View PDF files
    Exec=xpdf
    Icon=xpdf.xpm
    Terminal=false
    Type=Application
    MimeType=application/pdf;
    Categories=PDFViewer;Viewer;Graphics;

), touch(1) your mimeinfo.cache file if your corresponding .desktop file
is newer, and you're good to go. (Your mimeinfo.cache file must be seen
as newer than the .desktop file, else exo-open(1) will refuse to launch
the application noted in that .desktop file.)

Then, no matter what happens to the "system" mimeinfo.cache, your pre-
ferred application will remain the one associated with the MIME type.

Regards,
Eric
--
"The trouble with programmers is that you can never tell what a
programmer is doing until it's too late." --Seymour Cray (alleged)

Eric De Mund   | Ixian Systems           | Jab: eadixian at jabber.org/main
ead at ixian.com  | 650 Castro St, #120-210 | Y!M: ead0002
ixian.com/ead/ | Mountain View, CA 94041 | ICQ: 811788




More information about the conspire mailing list