Running a .sh from KDE launcher does not work

Hi, I’m trying to add a shortcut for a game called Starsector to my KDE launcher. The game runs via a .sh script. Running the .sh via Dolphin launches the game just fine. When I try running it from the launcher the launching animation (from KDE) plays but the game never starts. Is there any special configuration required for starting a .sh script from the launcher?

I tried searching for this online but all the hits are either for adding an application to launcher in general, not .sh specifically. And I get a lot of hits about auto starting applications which isn’t helpful either.

Some help would be much appreciated. Thanks in advance.

Try adding logging to the script to see if it runs at all and how far it runs.
The logging can be as simple as

echo Starting starsector.sh > /var/tmp/starsector.log

for me the menu entry usually wants a full Exec with bash, and Path set to the game folder.

Edit Application on that entry and try:
-Exec=/bin/bash /full/path/to/starsector.sh
-Path=/full/path/to/the/game/dir

if Path is empty it can flash the launch anim then die cause relative files miss. Dolphin already cds into the folder so that path works there.

This is strange. I just added a .sh launcher and it worked just fine. Maybe we need more info. But what @nite_route said should work.

I remember a bug where autostart scripts won’t start without a shebang. Maybe this is related. Make sure the script starts with this line (replace shell if needed):

#!/bin/bash

Also: is the executable bit set on the script?

on the advanced tab you can launch it in a terminal window and perhaps get more info on what is happening (or not happening) .

Was about to say this too, set it to run inside terminal (and not close after done). That way you can see if theres failure in the script

Try entering

sh -c '/path/to/script > ~/starcrash.log 2>&1'
or
bash -c '/path/to/script > ~/starcrash.log 2>&1'

Into the Program: field.

The resulting file should tell you what’s wrong.

If it doesn’t help, put sh -c 'env | sort > ~/envtest-l.txt' into that field, execute the launcher, then env | sort > ~/envtest-t.txt in a terminal, and lastly

diff -u ~/envtest*txt

You need to capture stderr as well where the errors usually go:

bash -c '/path/to/script &> \~/starcrash.log'

Hi everyone, thanks so much for your replies! I’m really grateful for the help.

In the end setting the path to the directory of the .sh was the solution.

I really appreciate all the advice for how to troubleshoot the issue via logging. I tried them all out, it should help out next time I run into any issues. And it gives me some practice in bash scripting and error piping.

For example piping the error stream into ~/starcrash.log gave me this error:

/home/herman/Games/starsector/starsector.sh: line 3: ./jre_linux/bin/java: No such file or directory

This wouldn’t have made it easy to figure out per se but its a good starting point for solving stuff myself.

Obligatory thanks to any KDE contributors in general as well for the great DE!

Would it be good if KDE Launcher set the working directory to the program directory by default? Or would that be bad practice somehow.

generally if the executable is in your $PATH then it’s not needed.

Spot on, nite_route1d! :rocket: That missing working directory is such a classic trap when launching shell scripts from the KDE app launcher compared to Dolphin. Explicitly setting the Path= property alongside /bin/bash fixes those relative path issues instantly. Great catch!

Not usually, because it’s more important to set the working directory to where your data to be processed is.

I assume things still aren’t working or you @gibibit would’ve said so?
And I still assume that this script Just Works if executed from a konsole window.

Is java local-installed under the game folder?

Does the launcher work if you set Path to the game folder as per spec?

If not, what exactly is on line 3 in that bash script?

How dumb of me!

I edited my previous comment.

However, your solution is bash-specific and we cannot assume that.

The issue was resolved by setting the working directory to the path of the shell script. Sorry if this was not clear before.