bashubuntuzenity

Ubuntu desktop entry based on bash script: How to access external files


I am learning bash and am working on a bash script that allows me to select a keyboard led-profile (keyboard-color-picker.sh).

The led-profiles are defined in external files (e.g. my-favorite-color-profile), placed in the same folder as the bash script itself. Such file is accessed like this in the script:

g213-led -p my-favorite-color-profile;;

When I run the bash script from terminal inside the parent folder, everything works as expected. As I wanted to run my bash script via launcher, I created a desktop file ~/.local/share/applications/color-picker.desktop, where the exec line points to my script:

Exec=/home/me/bin/keyboard-color-picker/keyboard-color-picker.sh 

Now my problem is, when envoked via launcher, the script does not seem to access the external files anymore. The profile defined in e.g. "my-favorite-color-profile" is not loaded.

What do I need to change so that my bash script runs via launcher the same way as it runs via terminal from the folder.


Solution

  • The underlying question is how to cd into the absolute path of my script, which is answered, e.g., here.