LinuxCommandLibrary

xdg-settings

Set default applications for file types

TLDR

Print the default web browser

$ xdg-settings get [default-web-browser]
copy

Set the default web browser to Firefox
$ xdg-settings set [default-web-browser] [firefox.desktop]
copy

Set the default mail URL scheme handler to Evolution
$ xdg-settings set [default-url-scheme-handler] [mailto] [evolution.desktop]
copy

Set the default PDF document viewer
$ xdg-settings set [pdf-viewer.desktop]
copy

Display help
$ xdg-settings --help
copy

SYNOPSIS

xdg-settings {get|set|check} category [value]
xdg-settings --list
xdg-settings --version
xdg-settings --help

PARAMETERS

get category
    Retrieves the currently configured default application for the specified category. For example, 'xdg-settings get default-web-browser'.

set category value
    Sets the default application for the specified category to value. The value is typically the .desktop file name (e.g., 'firefox.desktop'). For URL scheme handlers, it's the scheme itself (e.g., 'http' for 'default-url-scheme-handler http').

check category value
    Checks if the specified value is the default application for the given category. Returns an exit code indicating success (0) or failure (non-zero).

--list
    Lists all known categories for which default settings can be queried or set, along with their current default handlers.

--version
    Displays the version information for xdg-utils, which includes xdg-settings.

--help
    Shows a help message with usage instructions and available options.

category
    Represents the type of setting to manage. Common categories include default-web-browser, default-mail-client, and default-url-scheme-handler.

value
    Specifies the application or handler to be set or checked. For applications, this is usually the `.desktop` file name (e.g., `google-chrome.desktop`). For URL schemes, it's the scheme itself (e.g., `http`, `https`, `mailto`) followed by the desktop file.

DESCRIPTION

xdg-settings is a command-line utility that provides a standardized way to query and modify default application settings across various Linux desktop environments. It is part of the xdg-utils suite, developed by the freedesktop.org project to enhance interoperability and consistency on the desktop. This tool abstracts away desktop-specific configuration mechanisms, allowing users and scripts to manage preferences like the default web browser, mail client, or handlers for specific URL schemes (e.g., http, mailto). By offering a unified interface, xdg-settings ensures that applications can configure user preferences reliably, regardless of whether the user is running GNOME, KDE, XFCE, or other XDG-compliant environments. It is invaluable for system administrators, developers, and users seeking to automate or script desktop configurations.

CAVEATS

xdg-settings relies on the underlying desktop environment's proper implementation of XDG specifications. It may not function as expected in minimal window managers or environments that do not fully adhere to the XDG standards. The effectiveness can also be influenced by environment variables like `DESKTOP_SESSION` and `XDG_CURRENT_DESKTOP`. Specific desktop environment settings configured through graphical tools might sometimes override changes made via xdg-settings.

SUPPORTED CATEGORIES

Common categories supported by xdg-settings include: default-web-browser, default-mail-client, and default-url-scheme-handler. The default-url-scheme-handler requires an additional argument specifying the scheme, for example: `default-url-scheme-handler http`, `default-url-scheme-handler mailto`, `default-url-scheme-handler ftp`.

EXIT STATUS

The command returns an exit status of 0 upon successful execution. A non-zero exit status indicates an error or failure, which is useful for scripting and error handling.

DESKTOP FILES

When setting or checking default applications, xdg-settings typically expects the value to be the base name of a `.desktop` file (e.g., `firefox.desktop`), which describes an application and its capabilities according to the FreeDesktop.org Desktop Entry Specification.

HISTORY

xdg-settings is an integral part of the xdg-utils suite, developed under the auspices of the freedesktop.org project. This project emerged to bring standardization to various aspects of the Linux desktop, addressing the fragmentation caused by different desktop environments (GNOME, KDE, XFCE, etc.). The development of xdg-utils, including xdg-settings, was driven by the need for a common set of command-line tools that could abstract away desktop-specific configurations. This allows applications and scripts to perform tasks like opening files or setting default applications in a consistent manner across diverse desktop environments, thereby improving interoperability and user experience on the Linux desktop.

SEE ALSO

Copied to clipboard