Command line nerds1 say that graphical user interfaces are less efficient since the former use the keyboard and the latter tend to need the use of the mouse.
Graphical user interface fans say that command line based work-flows need the user to know more things about the system. Although I don't see why this would be an issue (what's the problem with getting to know better the system you use every day?), I can see one clear advantage to the point-and-click work-flow.
When the user wants to open a file, double-clicking on it just works. On the other hand, on the command line, the user needs to call the appropriate application and pass the file name as argument:
That means that the user has to know which is the application that is going to correctly deal with the given file. For example, this won't work:
evince is a document viewer and it only understands formats
dvi, but it is not able to
So how can one replicate the point-and-click behavior on the command line? It would be nice to have something like:
and that auto-magically the appropriate application was chosen.
It is of course possible, and it can be done in the same way as the graphical desktop environment does it: using xdg-utils.
Inside a desktop environment (e.g. GNOME, KDE, or Xfce), xdg-open simply passes the arguments to that desktop environment's file-opener application (gvfs-open, kde-open, or exo-open, respectively), which means that the associations are left up to the desktop environment. Therefore, on the command line, one can do:
and the appropriate application will be used (
evince on GNOME,
okular on KDE, etc.).
When no desktop environment is detected (for example when one runs a standalone window manager, e.g. stumpwm), xdg-open will use its own configuration files.
Sometimes, the default associations between applications and file
types may not suit the user. For instance, in my case,
were open with
mplayer, but I prefer
xdg-mime tool is
meant to help you change the default associations:
xdg-mime default vlc.desktop video/mp4
vlc.desktop parameter is an
xdg desktop file which describes
vlc applications. On my Debian GNU/Linux system, this files are
/usr/share/applications. So I was able to look in there
to see what applications
xdg-open could use.
video/mp4 passed to
xdg-mime is the type of file we
want to associate the application with. In order to know what type of
file we are dealing with,
xdg-mime can query it for you:
xdg-mime query my_movie.mp4
And the answer is:
Now, what happens if there is no desktop file for an application I want to use? For instance, remote sensing image visualization is not possible with the standard image viewers available on GNU/Linux. I personally use the OTB IceViewer, which is a lightweight application using the rendering engine developed for Monteverdi2.
In this case, I have to create a desktop file for the application. I
my case, I have created the
otbice.desktop file in
/home/inglada/.local/share/applications/ with the following contents:
[Desktop Entry] Type=Application Name=OTB Ice Viewer Exec=/home/inglada/OTB/builds/Ice/bin/otbiceviewer %U Icon=otb-logo Terminal=false Categories=Graphics;2DGraphics;RasterGraphics; MimeType=image/bmp;image/gif;image/x-portable-bitmap;image/x-portable-graymap;image/x-portable-pixmap;image/x-xbitmap;image/tiff;image/jpeg;image/png;image/x-xpixmap;image/jp2;image/jpeg2000;
The file has to be executable, so I have to do:
chmod +x /home/inglada/.local/share/applications/otbice.desktop
After that, I can associate the IceViewer with the image formats I want:
xdg-mime default otbice.desktop image/tiff
And it just works.