Linux File-Openers

This topic was published by and viewed 1713 times since "". The last page revision was "".

Viewing 1 post (of 1 total)
  • Author
    Posts

  • DevynCJohnson
    Keymaster
    • Topics - 437
    • @devyncjohnson

    Many users may be unaware that clicking an application in their desktop environment's menu is not activating the program immediately. Also, when right-clicking a file, how does the file-manager know which programs to recommend when viewing the "open with" sub-menu? A type of program called a "file-opener" is involved in both cases.

    A file-opener is a program that primarily manages the file associations. The default programs and mimetypes are remembered by the file-opener. Various file-openers exist, and most desktop environments have their own file-opener. However, xdg-open is a widely used file-opener that is independent of the type of desktop environment. Xdg-open commonly passes its information to the system's preferred file-opener. If the desktop interface does not have its own file-opener, then xdg-open will be the preferred choice.

    File-openers keep track of mimetypes that a program supports. If a user clicks a hyperlink (web address), the file-opener will look in its config files for the default web-browser. It will see that a particular program is associated with hyper-links and call that program (the web-browser) to go to the desired link. Otherwise, the user would need to open the browser manually and provide the link.

    Set Defaults
    Set Defaults

    Many desktop environments have a preferred file-opener, as mentioned before. Gnome uses gvfs-open, KDE Plasma uses kde-open, and Xfce uses exo-open. Some others include ayr, linopen, mimeo, mimi-git, expro, and busking-git.

    Mimetypes (also called "Internet media types") are special file and protocol identifiers. Files themselves do not contain mimetype data. Rather, the system looks for various data and features and assigns a mimetype. If the file's extension or magic-number (file format/type signature) are missing or changed, then the system may assign the wrong mimetype or use a vague mimetype. A mimetype consists of two parts - the type and subtype. For example, multi-purpose files (like a JavaScript file) are given the "application/javascript" mimetype. "application" (multi-purpose) indicates the type and "javascript" is the subtype. Some other types include "audio", "example" (not for general use), "image", "message", "model", "multipart", "text", "video", and some obscure types. Numerous subtypes exist. Obviously, I will not list them. Some users may have noticed various prefixes, as seen in "application/vnd.debian.binary-packag". In this example, the prefix is "vnd" which indicates the file is "vendor-specific". Another prefix is "x", and it is used for experimental or nonstandard file-types. However, that prefix is deprecated (http://tools.ietf.org/html/rfc6648). The mimetype standards can be seen here - http://tools.ietf.org/html/

    For more info on "Magic Numbers" - http://en.wikipedia.org/wiki/Magic_number_%28programming%29

    FUN FACT: Most Unixoid systems have a list of mimetypes stored in a file (/etc/mime.types).

    xdg-open is part of the xdg-utils (http://portland.freedesktop.org/xdg-utils-1.0/). In this toolkit is a program called xdg-mime. With this, the mimetype of a file can be identified. In a command-line, type "xdg-mime query filetype FILE" to figure out the mimetype of "FILE". Once the mimetype is known (given in the output), the user can see what program would open the file by default. To get that info, use this command "xdg-mime query default MIMETYPE". The output is a *.desktop file (commonly called a xdg-open script or a "desktop entry"). Use a plain-text editor to view the *.desktop file's contents. Look for the line starting with "Exec=". The command after the equal sign (=) calls the program to open the file. Now, the user knows what program opens the originally mentioned file (designated as "FILE").

    NOTE: Not only does xdg-utils use mimetypes but also HTML code and various web-applications.

    Using the xdg-mime tool, users can set defaults. To declare the default file-manager, type this command, but change "Nemo" to the desired file-manager - "xdg-mime default Nemo.desktop inode/directory". Be aware that a file-manager may not have a *.desktop file with the same name as the file-manager.

    Changing the defaults for a specific file-type is just as easy - [code]xdg-mime default evince.desktop application/pdf[/code].

    Changing the default web-browser via command-line requires a slightly different approach, as seen below. For convenience, it helps to know that firefox.desktop and chromium.desktop are the xdg-open scripts for Firefox and Chromium, respectively. Replace "BROWSER" below with the desired name.

    xdg-mime default BROWSER.desktop x-scheme-handler/http
    xdg-mime default BROWSER.desktop x-scheme-handler/https
    xdg-mime default BROWSER.desktop text/html
    xdg-open http://linux.org #test the change

    In many file-managers, the user can right-click a file and change the defaults. For instance, when using the Nautilus file-manager, right-click the file. Open the "Properties" and go to the "Open With" tag. Here, users can choose a default program for opening the right-clicked file. Alternately, the user can go to the "open with" submenu and open the file with a different program without making changes. However, some file-managers have an option in that same submenu to make a different program become the default program for that file-type.

    Set default "Open with"
    Set default "Open with"

    Many Linux systems come with a GUI-based program that allows users to more easily change and set defaults. If not, then users can install some from the repositories. Or, the user can manually edit the local mimetype association file (~/.local/share/applications/mimeapps.list).

    Once users understand how to change the defaults, then it becomes easier to use the system and complete tasks.

    Further Reading

    Attachments:
    1. Set default "Open with"
    2. Set Defaults
Viewing 1 post (of 1 total)