Need some help creating a .desktop file for a shell script

I need some help creating a functional .desktop file for a bash script.

The content of the script is

bash -c "{ leagueoflegends run /opt/wine-lol/bin/wine $HOME/.local/share/leagueoflegends/launchhelper/lhinjector.exe; } & leagueoflegends start"

I have tried

[Desktop Entry]
Type=Application
Name=League of Legends
Comment=League of Legends helper script
Path=/home/uname/.local/share/leagueoflegends/launchhelper/
Exec=lol
Icon=leagueoflegends
Terminal=false
Categories=Game;Wine;
StartupWMClass=leagueclientux.exe
[Desktop Entry]
Type=Application
Name=League of Legends
Comment=League of Legends helper script
Exec=bash -c "{ leagueoflegends run /opt/wine-lol/bin/wine $HOME/.local/share/leagueoflegends/launchhelper/lhinjector.exe; } & leagueoflegends start"
Icon=leagueoflegends
Terminal=false
Actions=kill;winecfg;
Categories=Game;Wine;
StartupWMClass=leagueclientux.exe

I have also tried

  • replacing the exec line with kitty -e bash -c [...]
  • replacing the exec line with sh -c [...]

None of these work. Running the script itself works. Running the content of the script works. The .desktop file does not work.

Try using full paths. /usr/bin/bash and the full path to leagueoflegends

No luck I’m afraid.

It might be easier to just create an actual script file and call the script file from the Exec in the desktop.

Make sure the script is set to be executable.

This was my original approach (if I understood you correctly), e.g:

[Desktop Entry]
Type=Application
Name=League of Legends
Comment=League of Legends helper script
Exec=/home/uname/.local/bin/scriptname
Icon=leagueoflegends
Terminal=false

I don’t know whether I’m meant to put bash in front of it when calling it in the exec line but neither seem to work.

Just a silly thought - were you expecting uname to be replaced with your username? Even using Exec=~/.local/bin/scriptname would be better, but simpler is to just use your name directly. And, to reiterate - are you sure the script is executable? I didn’t need to be for the bash -c construction, but otherwise…

If this is too obvious for words, just keep in mind it is the sort of thing I have done in the past :grin:

No I edited the path for the forum post. It does have execute permission and it works in a terminal.

-rwxr-xr-x 1 uname uname 145 Apr 29 04:37 /home/uname/.local/bin/lol

I was pretty sure it wasn’t needed! Can’t think why it isn’t working though - I have several such things going, and never have any trouble getting them to run. Full paths are all you need…

Good luck!

Thanks.

I’m wondering what the difference is between the methods that work and those that don’t.

  • calling the script in sxhkd works
  • calling the script in Hyprwm config works
  • calling the script in a terminal emulator works
  • calling the script via rofi spawned from a terminal emulator works
  • calling the script in a desktop file fails
  • calling the script in Awesomewm config fails
  • calling the script from rofi running via Awesomewm fails

Have you tried with Terminal=true ?
Read the specs and maybe you find what it needs.

This is the important bit. If it works in the terminal, it should also work with the desktop file. Most common mistake sometimes is that desktop files aren’t updated/refreshed even after editing them. You should go with the script and desktop file method

…and reboot/install dex and then run dex path_to_file.

https://forum.winehq.org/viewtopic.php?t=33865

1 Like

FWIW, dex can also create .desktop files :wink: . Read dex --help

1 Like

Same deal here unfortunately. Running dex path_to_file in a terminal emulator works. Running dex path_to_file from rofi or a window manager does nothing.

You could write your script to /usr/local/bin/script-name.
A good idea is to add this line as first in the script:

#!/bin/bash

Make sure you make it executable:

chmod +x /usr/local/bin/script-name

Then the Exec= line does not need bash prefix but only the script path:

Exec=/usr/local/bin/script-name

EDIT: are you sure your starting command is OK? I’ve not played that, but the line looks a bit strange to me. I may be wrong too…

Should the “Exec” line read “exec /usr/local/bin/script-name” ? as @manuel says the syntax looks a bit strange.

A desktop file, e.g. /usr/share/applications/xed.desktop has its syntax, where the command is written with line

Exec=xed %U

The thing after Exec= can be basically any command, with some small but obvious restrictions.

Is this what you meant?

Yes but I was questioning the syntax, including uppercase & lowercase letters. If /usr/local/ and all that stuff doesn’t work then it’s a mess. Wine is a pain in the ass!

Sorry, I don’t understand what you are asking.
Could be the language barrier as I don’t speak English natively.

That most likely means what you are doing relies on something that doesn’t exist in your environment but does exist in a terminal environment. That is why “calling the script via rofi spawned from a terminal emulator works” and “calling the script from rofi running via Awesomewm fails”

2 Likes

Sorry, just thought command could be wrong.