Using relative paths for Gnome launcher

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 00:44:10

Relative paths are not supported*.

One solution is to have an installer. This script updates the desktop file according to the location the script is run from. Make the script executable, and the user can click it to install. The script requires the desktop file to be writable.

This was done with Linux in mind. The file is named autorun.sh; but that is just a convention, it usually won't run automatically. If you deploy this on something other than Linux, then name the file something else(autorun.linux), or adapt it to do different things according to the platform.

#! /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"

*The convention for the freedesktop is to have the icons in $HOME/.icons, /usr/share/icons or /usr/share/pixmaps. Under those directories are subdirectories for different icon sizes and types. When using one of those directories to store the icon, only the icon name(without the directory) is listed in the desktop file; otherwise record the full path to the file.

The executable, if in the path, can be listed with no pathname(unsafe). It's best to list the full path. Imagine the wrong program getting launched because the full path isn't specified.

Another possibility is to copy the desktop file to the user's desktop or to /usr/share/applications, and edit it there. Do this when the program is on read-only media.

Because none of the above results in a true install, if possible, use the platform's native installer and packaging tools(rpm,dep,portage, etc.). Those tools provide a framework for complete installation including the proper file permissions(think selinux), and desktop menus. They also provide for easy uninstall.

If the program has to run from the removable media, consider using the system install for just installing symlinks, maybe to /opt/vendor/progname.

What I did and worked perfectly was:

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

Explaining the command:

The snippet below will get the dir name of who is executing that, therefore the launcher dir name

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

So appending the desired path, will make this execute relative path.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!