Jak*_*les 14 linux desktop shortcut
对于我的一个Linux应用程序,我有应用程序二进制文件,一个launcher.sh脚本(用于LD_LIBRARY_PATH)和一个.desktop文件,它们都在同一个文件夹中.
我想使用相对路径而不是图标的绝对路径.
我试过了:
Icon=app.svg
Icon=./app.svg
Icon=$PWD/app.svg
Icon=$(dirname %k)/app.svg
Run Code Online (Sandbox Code Playgroud)
但这些都没有(仅Icon=/path/to/app.svg).如果无法指定相对路径并且我必须使用解决方法,那么每次运行launcher.sh脚本时我都认为我可以在.desktop文件中重新生成图标路径.
最好的方法是什么?sed或者像伪正则表达式那样使用或者其他一些替换实用程序Icon=([valid path chars]+)\n?
Jak*_*les 15
在做了一些更多的研究之后,就我所见,它看起来似乎不可能为桌面条目文件中的图标指定相对路径.
我使用的解决方法是将以下代码添加到我的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
Run Code Online (Sandbox Code Playgroud)
这将在每次运行启动器脚本时更新图标的路径,并且由于.desktop文件指向启动器脚本,因此单击.desktop文件可以有效地更新其图标.
我知道你可以使用cat或-i选项来缩短上面的代码,但我已经读过我使用的解决方案更可靠.如果有人有进一步的信息,请发表评论.
It's true that the FreeDesktop specification does not permit relative paths:
Standard Keys
IconIcon 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.
[ . . . ]
Values of type
iconstringare the names of icons; these may be absolute paths, or symbolic names for icons located using the algorithm described in the Icon Theme Specification. Such values are not user-displayable, and are encoded in UTF-8.
The workaround is adequate,
although it probably won't work for menus and panel launchers.
But if you're comfortable patching the desktop file
when running the launcher.sh script,
why not actually install the icon?
You can do it in two lines:
cp app.svg ~/.local/share/icons/hicolor/48x48/apps/
cp app.svg ~/.local/share/icons/hicolor/scalable/apps/
Run Code Online (Sandbox Code Playgroud)
and then put
Icon=app
Run Code Online (Sandbox Code Playgroud)
in the desktop file (app is just the filename without a file extension).
This is the intended mechanism for locating icons that don't have an absolute path, and will ensure the icons show up in menus and custom launchers. The spec has this to say:
So, you're an application author, and want to install application icons so that they work in the KDE and Gnome menus. Minimally you should install a 48x48 icon in the hicolor theme. This means installing a PNG file in $prefix/share/icons/hicolor/48x48/apps. Optionally you can install icons in different sizes. For example, installing a svg icon in $prefix/share/icons/hicolor/scalable/apps means most desktops will have one icon that works for all sizes.
One way this can be done
is with the xdg-icon-resource command, e.g.
$ xdg-icon-resource install --novendor --context apps --size 48 example-app.png
Run Code Online (Sandbox Code Playgroud)
However, xdg-icon-resource
does not support SVG images,
and in practice this accomplishes the same thing:
$ cp example-app.svg ~/.local/share/icons/hicolor/48x48/apps/
$ cp example-app.svg ~/.local/share/icons/hicolor/scalable/apps/
Run Code Online (Sandbox Code Playgroud)
(That's not a typo: put the SVG file in the 48x48/apps folder
and the menus and panels will be perfectly happy.)
For menus, it's a good idea to update the icon cache after installing.
$ update-icon-caches ~/.local/share/icons
Run Code Online (Sandbox Code Playgroud)
Then you can simply give the iconstring as example-app like this:
Icon=example-app
Run Code Online (Sandbox Code Playgroud)
This is not a relative path, but it solves the problem of having to use an absolute path and won't break if the desktop file is moved to a different location.
For what it's worth, support for relative paths was discussed on the FreeDesktop mailing list back in September 2008:
Magnus Bergmark magnus.bergmark at gmail.com
Tue Sep 23 01:01:32 PDT 2008
[ . . . ]
I propose that we allow the usage of relative paths in some way also.
Use-cases
I use a lot of .directory files to make directories containing a movie have the movie poster as the icon. This behaviour could apply to any form of media, like comic books, music (album art) and photos.
A vendor might want to bundle an icon to a piece of software they're distributing to go with a .desktop file which are not to go in the desktop menu and therefore are still located in the application directory.
https://lists.freedesktop.org/archives/xdg/2008-September/009940.html
The only counterargument I was able to find to this proposal is here:
A .desktop file that is not intended to go into a standard applications directory is almost entirely useless. Perhaps you should look at some of the software bundle proposals and implementations, and work with using those, instead. Another option is the xdg utils scripts, to install the .desktop file and icons in the appropriate places. I can only presume that your uninstalled application also intends to not follow the Icon Theme and Icon Naming specifications either. And I don't see setting the directory's icon as useful really. Setting an icon for the actual executable would be much more useful, though elf binaries do not have resources like win32 binaries do.
https://lists.freedesktop.org/archives/xdg/2008-September/009962.html
Related questions:
Relevant links:
| 归档时间: |
|
| 查看次数: |
4348 次 |
| 最近记录: |