How can I set the 'Path' variable in a .desktop file to be relative to the location where the desktop file is located?
You can kludge around this by using an in-line bash mini-script on your Exec. This will add the .desktop file's path to PATH prior to running your command.
Exec=bash -c "export PATH=$PATH:`dirname %k`; your_command"
%k will be substituted by the path of the desktop file itself. The dirname
command chops off the filename part, leaving only the directory. Once PATH is set like this, your_command
can be invoked without a full path.
You cannot set the CWD inside a .desktop file. If you want an application to have a specific CWD, you will need to write a simple wrapper script for the application, that looks something like this:
#!/bin/sh
(cd /where/you/want/it/to/be && exec your_program)
You can replace your_program
there with $@
and run the script with your_program as an argument, like run-in-dir.sh your_program
. This way you can use the same script to wrap any program you want to start in that directory.
I used this:
Exec=bash -c 'cd $(dirname %k) && ./SCRIPT_NAME'
The %k is the full name of the .desktop file including its path. It's then used by dirname to get a location and change directory to that location. Finally, now that it's in the right place, it finds the script and runs it.