Skip to content

Ferdinand Agyei-Yeboah

Linux Desktop File Entries

March 22, 2022

Background

Desktop entry files, .desktop, are used to create shortcuts (taskbar and search) for installed applications. Generally polished linux installers for a program (ex: Google) will create a .desktop file for you as part of the install process. If you’ve installed a program, and no shortcut is created, then most likely a .desktop file was not created as part of the installation process. No fear, it is a simple process to create one for any installed program.

.desktop files should be stored in /usr/share/applications (global, for all users) or ~/.local/share/applications (per user)

Example Of Linux Desktop Entry File - VSCode

[Desktop Entry]
Name=Visual Studio Code
Comment=Code Editing. Redefined.
GenericName=Text Editor
Exec=/usr/share/code/code --unity-launch %F
Icon=com.visualstudio.code
Type=Application
StartupNotify=false
StartupWMClass=Code
Categories=Utility;TextEditor;Development;IDE;
MimeType=text/plain;inode/directory;application/x-code-workspace;
Actions=new-empty-window;
Keywords=vscode;
X-Desktop-File-Install-Version=0.24
[Desktop Action new-empty-window]
Name=New Empty Window
Exec=/usr/share/code/code --new-window %F
Icon=com.visualstudio.code

Important things to note here

  • Exec is the command to execute for the program
  • You can add an entry for each action you want on your shortcut. Ex: New Empty Window, Incognito, New Document, etc… The action maps to a command (which might pass certain arguments), this means you do have to know what command to use to each action.
  • Icon determines what picture to show for shortcut. It can be a path to a local file.

Other questions

  • How does linux find the .desktop files?
    • It’s determined by the $XDG_DATA_DIRS environment variable. This contains a list of paths to check in precedence order. You can see flatpak added it’s own path to this.
  • How are icons found if not using a file path?
    • According to icon theme spec

Links:


Software Engineering Tutorials & Best Practices