Why do freedesktop .desktop files not allow relative paths

desktopdesktop-environmentfreedesktopicons

The .desktop files have become the de-facto standard to easily access applications on Linux desktops, with executables not being easily startable from the GUI otherwise and many launchers not using the app icon but only the icon specified in the .desktop file.

Why then, does it not seem possible to use .desktop files that specify a relative path to their executable and is there a way around this?

When shipping software that one does not want to force users to install, relative paths are the only way to enable this.

AppImage seems to work around this by installing a .desktop file when being run for the first time by the user, which seems like a kludgy way to enable icons and launchers for software with a flexible path. Relative paths would be a much better way to go. Why is this solution then not possible on Linux desktops? It seems unlikely that this is a mere oversight but that I am instead missing the deeper reason behind this decision.

Best Answer

You could use an inline shell script to compute the path:

Exec=sh -e -c "exec \\"\\$(dirname \\"\\$0\\")/some_app\\"" %k

Yes, two levels of escaping are required.

Related Question