4

We're developing an app that needs to run on a removable device (e.g. USB stick). On Linux, we're using Gnome launchers to place a shortcut to the app on the root of the device. However, we need to use relative paths for the executable and icon since we don't know in advance where the device will mount. In the .desktop file I have something like:

Exec=../myapp/myexecutable
Icon=../myapp/myicon.png

Neither the executable or icon is found. I read the spec on icon lookup in .desktop files (http://standards.freedesktop.org/icon-theme-spec/icon-theme-spec-latest.html#icon_lookup) but it didn't enlighten me.

Is there a way to get launchers to use a relative path? If not, is there another approach to achieve what I want (i.e. a shortcut with an icon and an executable, specified using relative paths)?

4

2 回答 2

3

不支持相对路径*。

一种解决方案是安装安装程序。此脚本根据运行脚本的位置更新桌面文件。使脚本可执行,用户可以点击安装。该脚本要求桌面文件是可写的。

这是在考虑 Linux 的情况下完成的。该文件名为autorun.sh;但这只是一个约定,它通常不会自动运行。如果您将它部署在 Linux 以外的其他东西上,则将该文件命名为其他名称(autorun.linux),或者根据平台对其进行调整以执行不同的操作。

#! /bin/sh

####  Fixup $APPNAME.desktop.
APPNAME=xvscatter
ICONNAME=xv_logo.png

cd $(dirname "$0")
APPDIR="$PWD/$APPNAME"
EXEC="$APPDIR/$APPNAME"
ICON="$APPDIR/$ICONNAME"

sed -i -e "s@^Icon=.*@Icon=$ICON@" \
    -e "s@^Exec.*@Exec=$EXEC@"  "$APPNAME.desktop"

* freedesktop的惯例是将图标放在 $HOME/.icons、/usr/share/icons 或 /usr/share/pixmaps 中。在这些目录下是不同图标大小和类型的子目录。当使用其中一个目录来存储图标时,桌面文件中只列出图标名称(不包括目录);否则记录文件的完整路径。

可执行文件,如果在路径中,可以不带路径名(不安全)列出。最好列出完整路径。想象一下由于未指定完整路径而启动了错误的程序。

另一种可能性是将桌面文件复制到用户的桌面或/usr/share/applications,并在那里进行编辑。当程序在只读媒体上时执行此操作。

因为以上都不会导致真正的安装,如果可能,请使用平台的本机安装程序和打包工具(rpm、dep、portage 等)。这些工具为完整安装提供了一个框架,包括正确的文件权限(想想 selinux)和桌面菜单。它们还提供轻松卸载。

如果程序必须从可移动媒体运行,请考虑使用系统安装来仅安装符号链接,可能是 /opt/vendor/progname。

于 2010-10-07T06:02:42.800 回答
0

我所做并完美工作的是:

Exec=sh -e -c "exec \\"\\$(dirname \\"\\$0\\")/.sh/server.sh\\";$SHELL" %k

解释命令:

下面的代码片段将获取执行者的目录名称,因此启动器目录名称

$(dirname \\"\\$0\\")

所以附加所需的路径,将使这个执行相对路径。

参考:https ://askubuntu.com/questions/1144341/execute-shell-on-a-relative-path-on-ubuntu-launcher

于 2019-05-18T20:00:37.027 回答