0

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.

5
  • You can cd in your script for example Commented Sep 21, 2022 at 17:49
  • Nice, it works when I cd into the absolute path of the script. Then I wanted to make it more general, but when I tried cd $(pwd) instead, it again does not work when run via launcher Commented Sep 21, 2022 at 18:35
  • $(pwd) does not expand to the absolute path of the script Commented Sep 21, 2022 at 18:36
  • got it, so to determine the location of a script being run, I ended up using the top answer from here, which also worked Commented Sep 21, 2022 at 18:55
  • 1
    You may now write an answer for your own question if you want Commented Sep 21, 2022 at 18:56

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.