XDG (Cross-Desktop Group) is a group of specifications from freedesktop.org covering several desktop issues. There are some programs that make use of these specifications to manage desktop environment settings.

Table of Contents

Autostart

Some applications create an entry inside /etc/xdg/autostart/ (system) or $USER/.config/autostart/ (user) during its installation to be able to start during the startup of a desktop environment (after the user has logged in). User-defined entries override system-wide ones with the same filename.

Entries are Desktop Entries (like the ones you use to create desktop icons or Program Menu entries). This is an example (/etc/xdg/autostart/org.kde.kdeconnect.daemon.desktop):

[Desktop Entry]
Type=Application
Exec=/usr/lib/kdeconnectd
X-KDE-StartupNotify=false
X-KDE-autostart-phase=1
X-KDE-Wayland-Interfaces=org_kde_kwin_fake_input
X-GNOME-Autostart-enabled=true
NoDisplay=true
Icon=kdeconnect

Name=KDE Connect

To disable a system-wide entry, you can either remove the entry (or move it to another folder), or create a user-defined file with the same filename, copying its content and appending this line:

Hidden=true

To be able to use XDG Autostart, you need a use a desktop environment that supports it, or a dedicated implementation.

xdg-utils

xdg-utils is a set of tools that allows applications to easily integrate with the desktop environment of the user, regardless of which desktop environment the user runs. You don’t usually need to manually run these tools, but you can do it for troubleshooting purposes.

  • xdg-open: opens a file or URL in the user’s preferred application.
    xdg-open myfile.txt
    
  • xdg-mime: command line tool for querying information about file type handling.
    • Determine a file’s MIME type:
      $ xdg-mime query filetype urls.txt.asc
      application/pgp-encrypted
      
    • Determine the default application for a MIME type:
      $ xdg-mime query default image/jpeg
      org.kde.gwenview.desktop
      
    • Change the default application for a MIME type:
      xdg-mime default gimp.desktop image/jpeg
      

      The ‘application’ is the desktop file id of the application and has the form vendor-name.desktop. Application must already be installed in the desktop menu before it can be made the default handler. The application’s desktop file must list support for all the MIME types that it wishes to be the default handler for.

  • xdg-settings: get various settings from the desktop environment.
    • Get default web browser:
      $ xdg-settings get default-web-browser
      com.brave.Browser.desktop
      
    • Change default web browser:
      xdg-settings set default-web-browser google-chrome.desktop
      

      As with xdg-mime, the ‘application’ is the desktop file id of the application.

  • xdg-desktop-icon: install (or uninstall) an application launcher or other file on the desktop of the current user.
    xdg-desktop-icon install ./myapp.desktop
    
    xdg-desktop-icon uninstall myapp.desktop
    
  • xdg-desktop-menu: install (or uninstall) new menu entries to the desktop’s application menu.
    xdg-desktop-menu install myapp.desktop
    
    • Add also a submenu (.directory files are similar to .desktop, with Type=Directory instead of Type=Application):
      xdg-desktop-menu install mymenu.directory myapp.desktop
      
  • xdg-icon-resource: install (or uninstall) icon resources into the desktop icon system. Icon resources can be PNG or XPM files.
    xdg-icon-resource install --size 64 myapp-icon.png
    

Check manpages of these tools for more info.

If you have any suggestion, feel free to contact me via social media or email.