Managing .desktop files on Ubuntu

16/09/2024

An extremely quick guide to create, manage and refresh the list of .desktop files on Ubuntu

Structure of basic .desktop file

[Desktop Entry]
Name=PrusaSlicer
GenericName=3D Printing Software
Icon="/path/to/icon"
Exec="/path/to/executable" %F
Terminal=false
Type=Application
MimeType=model/stl;application/vnd.ms-3mfdocument;application/prs.wavefront-obj;application/x-amf;
Categories=Graphics;3DGraphics;Engineering;
Keywords=3D;Printing;Slicer;slice;3D;printer;convert;gcode;stl;obj;amf;SLA
StartupNotify=false
StartupWMClass=prusa-slicer

Where are .desktop files located on Ubuntu (22.04)?

/usr/share/applications
~/.local/share/applications

The issue

When I create a new .desktop file, sometimes Ubuntu’s search doesn’t refresh its list and the newly added application doesn’t show up.

The fix

xdg-desktop-menu forceupdate

This istantly updates Ubuntu’s search results.

Useful commands

This command should be silent if everything goes well:

desktop-file-validate /path/to/file.desktop

Additional resources

Arch Linux Wiki - Desktop entries

Stack Exchange discussion - Why are my application.desktop files not showing up in Linux application menu?

All posts
davespace.xyz – 2024