如何为Linux桌面条目文件指定带有相对路径的图标? [英] How can I specify an icon with a RELATIVE path for a Linux desktop entry file?

查看:438
本文介绍了如何为Linux桌面条目文件指定带有相对路径的图标?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于我的一个Linux应用程序,我具有应用程序二进制文件,launcher.sh脚本(用于LD_LIBRARY_PATH)和.desktop文件,它们都位于同一文件夹中.

我想为图标使用相对路径,而不是绝对路径.

我尝试过:

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

,但这些都不起作用(仅Icon=/path/to/app.svg).如果无法指定相对路径,而我必须使用一种解决方法,那么我想我可以在每次运行launcher.sh脚本时重新生成.desktop文件中的图标路径.

做到这一点的最佳方法是什么?将sed或其他替代实用程序与伪正则表达式一起使用,例如Icon=([valid path chars]+)\n吗?

解决方案

经过更多研究后,据我所知,似乎不可能为桌面条目文件中的图标指定相对路径. /p>

我使用的解决方法是将以下代码添加到launcher.sh脚本的末尾:

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

这将在每次运行启动脚本时更新图标的路径,并且由于.desktop文件指向启动脚本,因此单击.desktop文件可以有效地更新其图标.

我知道您可以使用cat或-i选项来缩短上面的代码,但是我已经读到我使用的解决方案更可靠.如果有人对此有进一步的信息,请发表评论.

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?

解决方案

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.

这篇关于如何为Linux桌面条目文件指定带有相对路径的图标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆