Ubuntu – .desktop file running sh script “There was an error launching the application.”

command linedesktop

I have a .desktop file:

[Desktop Entry]
Type=Application
Terminal=true
Name=RunMe
Exec=run.sh

When I double click the .desktop file, I get There was an error launching the application.

my run.sh is:

#!/bin/sh
xulrunner-sdk/bin/xulrunner-stub --app xulrunner-sdk/bin/application.ini 2>~log.log

Double clicking on run.sh and clicking run runs the application fine. Both run.sh and my .desktop are executable.

What do I need to change in my desktop file to make this work?

Best Answer

%k is the desktop file path, use it with sh to relative .desktop:

  • Change current working directory (pwd), Then run.sh & commands inside all will run from there:

    [Desktop Entry]
    Type=Application
    Terminal=true
    Name=Run Me
    Exec=sh -c "cd `dirname %k`; run.sh"
    
  • Otherwise, passing it as parameter to run.sh and use it explicitly when you need inside run.sh:

    run.desktop

        [Desktop Entry]
        Type=Application
        Terminal=true
        Name=Run Me
        Exec=sh -c "`dirname %k`/run.sh `dirname %k`"
    

    run.sh

        #!/bin/sh
        $1/xulrunner-sdk/bin/xulrunner-stub --app $1/xulrunner-sdk/bin/application.ini 2>$1/~log.log
    

Reference: How can I set the 'Path' variable in a .desktop file to be relative to the location where the desktop file is located?