How to automatically detect username when setting file path for icon

Solution 1:

.desktop files are hardcoded. They do not support bash expansions or variables.

The approach to go about this here is to specify the icon by its file name without extension in the .desktop file, as in:

Icon=myicon

Then have the icon, customized for the user, installed in ~/.local/share/icons or ~/.icons, e.g ~/.local/share/icons.png.

An icon file installed in these user configuration directories will take precedence over systemwide installed icons with the same file name (/usr/local/share/icons, or /usr/share/icons for applications installed using the package management system).