Idea about generic command framework for launching common applications
François Revol
revol at free.fr
Mon Nov 17 12:33:53 PST 2008
For what it's worth, here is how it's done in BeOS and Haiku.
Each application has a mime signature.
For example, the default image viewer in BeOS, ShowImage has the type:
application/x-vnd.Be-ShowImage
Each application also exports a resource (that is copied to an xattr)
describing the mime types it supports.
http://dev.haiku-os.org/browser/haiku/trunk/docs/userguide/filetypes-images/filetype-addon-stylededit.png
shows this with the pretty names (text being the supertype, and "Text
File" being text/plain).
The mime database has a preferred handler set by either its mime type
or its path, which can be overridden for each file by setting an xattr:
http://dev.haiku-os.org/browser/haiku/trunk/docs/userguide/filetypes-images/filetype-addon.png
Then it becomes quite easy to open the default application for a mime
type, or force using another one.
In Haiku one can do
open application/x-vnd.beunited.pe foo.txt
to force openning foo.txt with the Programmer Editor instead of the
default app (StyledEdit), regardless of where it is installed (the
system runs a query on the BEOS:APP_SIG xattr).
The setmime command provides CLI access to the mime db, for ex:
$ setmime -dump text/html
/bin/setmime -set text/html -short "HTML File" -preferredAppSig
application/x-vnd.Firefox -sniffRule '0.40 [0:64]( -i "<HTML"
| "<HEAD" | "<TITLE" | "<BODY" | "<TABLE" | "<!--" | "<META" | "<
CENTER")' -extension htm -extension html
(it doesn't dump icon hex data by default)
We also use a mime type to specify url handlers:
$ setmime -dump application/x-vnd.Be.URL.http
/bin/setmime -set application/x-vnd.Be.URL.http -preferredAppSig
application/x-vnd.Firefox
And a simple
/bin/setmime -set application/x-vnd.Be.URL.http -preferredAppSig
application/x-vnd.NetSurf
/bin/setmime -set text/html -preferredAppSig application/x-vnd.NetSurf
would make NetSurf the default browser
The only lack would be differentiation between viewing and editting,
though there is provision for it in the API, but currently B_OPEN is
the only defined verb.
François.
More information about the xdg
mailing list