Ubuntu – Icon path in .desktop file

desktopiconspaths

On my desktop I have a .desktop file. If I type:

Icon=/home/ianbell/Pictures/myLogo.png

the icon of the .desktop file changes (the expected result).

But, if I type:

Icon=~/Pictures/myLogo.png

it doesn't work.

Isn't ~/ a shortcut for /home/$USER?

Best Answer

The use of paths in a .desktop file

In a .desktop file, you need to use absolute and full paths. Therefore ~ is not expanded.

This is a commonly made mistake :)

Exceptions concerning icons are a.o. described here:

Icon to display in file manager, menus, etc. If the name is an absolute path, the given file will be used. If the name is not an absolute path, the algorithm described in the Icon Theme Specification will be used to locate the icon.

and here:

Icon field is the icon that should be used by the launcher and represents the application. All icons that are under the directory /usr/share/pixmaps don't need to have their full path specified, but their filename without the extension. For example, if the icon file is /usr/share/pixmaps/wallch.png, then the Icon field should be just 'wallch'. All other icons should have their full path specified.

More information

In a .desktop file:

In the Icon= line, you are allowed to use spaces:

Icon=/home/jacob/Thema/icon/some folder/some icon.png

is fine.

However

In the Exec= line, you are not allowed to use spaces, unless in case of an argument. In all other cases, you need to quote the path steps with a space:

Exec=/home/jacob/Bureaublad/some folder/application

will fail, while

Exec="/home/jacob/Bureaublad/some folder/application"

or

Exec=/home/jacob/Bureaublad/"some folder"/application

will work fine

Related Question