4

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?

6

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.

0

You can try something like this:

[Desktop Entry]
Type=Application
Name=MyApp
Exec=sh -c "mv %k %k-bak && sed -e "s,^Icon=.*,Icon=$HOME/.bin/path/to/icon.png,g" %k-bak > %k && chmod +x %k; rm %k-bak"
Icon=???

This will add the relative Icon path to the .desktop file after you run it.

Some more details:

%kstands for the path of the .desktop file

  1. mv %k %k-bak creates a backup file

  2. sed -e "s,^Icon=.*,Icon=$HOME/.bin/path/to/icon.png,g" ... replace the old Icon path with the current $HOME... path ("^" -> beginning line, is here really importand to not replace the command self) and create the new .desktop file

  3. chmod +x %k make the new .desktop file executable

  4. rm %k-bak remove the old backup file

You can add your own commands after the Icon path was changed or before.

Inspired by https://stackoverflow.com/a/3464561 and https://askubuntu.com/a/345123/265974

  • i don't have root access, so I can't use /usr/share.... and I want to sync the starter between different computers, which is why I need a more generic soluteion with $HOME or something like this... – Jonas Jun 3 '14 at 15:41
  • @Jonas i've updated my answer. – TuKsn Jun 3 '14 at 22:24
  • 1
    thanks! Yes that might work...but isn't there any easier solution? Why does gnome shell not evaluate environment variables? – Jonas Jun 4 '14 at 9:08
  • Sorry i dont't know. – TuKsn Jun 4 '14 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.