Ubuntu – How to set the ‘Path’ variable in a .desktop file to be relative to the location where the desktop file is located

xdg

I want to set the 'Path' variable in a .desktop file relative to the location where the desktop file is located and I can't manage to do that.

When I don't declare it or set it to blank it defaults to my home folder no matter where I run it from; and it doesn't accept values relative to my current location within the file system.

Best Answer

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.