How to include environment Variable in launcher for icon

This is an extension to the question how to include an environment variable in the launcher? . This question explains how to use the environment variable for the Exec part of the .desktop file but not the icon

an example:

[Desktop Entry]
Name=My Application name
Comment=a comment
Exec=sh -c '$HOME/.bin/path/to/bin'
Icon= $HOME/.bin/path/to/icon

This Launcher will work but the icon is not shown. I can't use something like

Icon=sh -c '$HOME/.bin/path/to/icon'

for the icon... what to do instead?


Honestly the best way to use an icon in a launcher is to make sure the icon file is in the icon search path. Referring to the freedesktop.org icon directory scheme and base directory definitions, icons should be searched for in at least the following directories on Ubuntu systems:

  • $HOME/.icons
  • $HOME/.local/share/icons
  • /usr/local/share/icons
  • /usr/share/icons
  • /usr/share/pixmaps

So if you want to use your own icon and do not have root privileges, install the icon into either $HOME/.icons or $HOME/.local/share/icons. Using the latter, you can even mimic the system icon directory structure with multi-resolution icons using the same base name under directories like $HOME/.local/share/icons/hicolor/48x48/apps and $HOME/.local/share/icons/hicolor/256x256/apps.

If the icon is in one of these searchable directories, you can simply use Icon=myapp in the .desktop file.