views:

28

answers:

1

For one of my Linux applications, I have the application binary, a launcher.sh script (for the LD_LIBRARY_PATH) and a .desktop file, all in the same folder.

I'd like to use a relative path rather than an absolute path for the icon.

I've tried:

Icon=app.svg
Icon=./app.svg
Icon=$PWD/app.svg
Icon=$(dirname %k)/app.svg

but none of these work (only Icon=/path/to/app.svg). If it's not possible to specify a relative path and I must use a workaround, I was thinking I could regenerate the icon path in the .desktop file every time the launcher.sh script is run.

What would be the best way to do that? Using sed or some other replacement utility with a pseudo-regex like Icon=([valid path chars]+)\n perhaps?

A: 

After doing some more research it doesn't look like it's possible to specify relative paths for an icon in a desktop entry file as far as I can see.

The workaround I used was to add the following code to the end of my launcher.sh script:

mv myapp.desktop myapp.desktop-bak
sed -e "s,Icon=.*,Icon=$PWD/app.svg,g" myapp.desktop-bak > myapp.desktop
rm myapp.desktop-bak

This will update the path of the icon each time the launcher script is run, and since the .desktop file points to the launcher script, clicking the .desktop file effectively updates its icon.

I know you could use cat or the -i option to shorten the above code but I've read that the solution I used is more reliable. If anyone has further information on that please do post a comment.

Jake Petroules