31

I created a my-app.desktop file for a program I wrote. When I double-click it, I get the error message "There was an error launching the application". How can I get more detailed information about what the problem is?

I saw a reference to a "details" section of the dialog box, but there is nothing like that present in the one I see. If I were on my Mac, I'd open the Console app to see if any errors were logged, but I haven't learned of anything similar on Ubuntu.

(Note that unlike other similarly-titled questions, I am not asking what's wrong with this particular .desktop file; I want to know how to find out in general.)

7
  • 1
    I would just run the Exec line from the terminal and see what the output tells you, but are you sure the desktop file is ok? maybe you should check and run it from the terminal as well. Mar 20, 2014 at 17:51
  • @Jacob If there is a way to "run it from the terminal" that puts something useful on stderr, that would constitute an answer to this question.
    – Kevin Reid
    Mar 20, 2014 at 17:56
  • 1
    @terdon I tried that, and it turned out that (as the next problem) the environment was different in a way that mattered. I want to know how to get more information out of the normal launch process so that I'm not guessing at what's different.
    – Kevin Reid
    Mar 20, 2014 at 18:25
  • 3
    @terdon Empirically, running it in the terminal is different — I tried and it was different (in particular a different PATH). I want to know how to get exactly the same environment as a normal launch but with more diagnostic info.
    – Kevin Reid
    Mar 20, 2014 at 18:38
  • 3
    A bit offtopic, but 9 times of 10 that problem airs it is special characters, like spaces, in Exec= path. Remember, you should have Exec= in quotes and Path= without quotes. Sep 24, 2016 at 14:06

7 Answers 7

27

Found an answer to this question here: https://askubuntu.com/a/836842

Try this :

desktop-file-validate my-app.desktop

It outputs errors in your .desktop file. For example mine returned :

error: first group is not "Desktrop Entry"

So once I corrected the typo to Desktop Entry, the script ran successfully.

1
  • This should be the solution. The chosen solution above is tedious and fragile.
    – Matt
    Mar 1, 2020 at 22:04
16

Here's a trick you can use. Create a wrapper script for your application that will launch it and capture the error output:

#!/usr/bin/env bash

## Launch 'yourapp' and capture its standard error output
/path/to/yourapp 2>~/myapp.log

Save that as ~/foo.sh and make it executable with chmod +x ~/foo.sh. Now, point your desktop launcher to it instead. Something like:

[Desktop Entry]
Version=2.0
Type=Application
Exec=/home/kevin/foo.sh
Terminal=true
Comment=My app!

That will redirect any error messages to ~/myapp.log and you can examine them at your leisure. You can use 2>>~/myapp.log if you want successive error messages to be appended to the file instead of overwriting it.


As an aside, the reason that the $PATH is different is because you are probably setting your $PATH in ~/.bahsrc which is not read by the graphical environment. It is also a bad idea since the $PATH will be set every time you open a new terminal and that is needless overhead. Use ~/.profile for this instead. For more details on which files are read when see here and for more on which file should be used for what, see here.

1
  • Didn't found the problem this way, but the wrapper was working, so I just kept the wrapper as the executable. Jan 29, 2018 at 18:49
12

By running the following command in terminal:

awk -F= '/Exec=/{system($2)}' your_desktop_file.desktop

I am sure that you will find out if there is an error or not in your command assigned to the Exec field from inside of your .desktop file.

4
  • 6
    I've a similar problem. i execute your command and my.desktop file work perfectly. But when i double click it ,it shows There was an error launching the application Jul 10, 2016 at 19:02
  • 1
    This answer is kind of funny, since (even though I don't think it does any-much-more than running Exec value in the shell) it made me realize TryExec key was my problem.
    – mirh
    Dec 4, 2018 at 23:13
  • If you have a complicated Exec command, you have to wrap it in bash script, like it shown in the accepted answer (and don't forget to give it chmod a+x your.sh executable rights)
    – madzohan
    Apr 9, 2020 at 6:35
  • Thank you, calling this made me find there was a wrong path in my Exec= line at the *.desktop file I'm editing Jul 2, 2020 at 12:37
3

usually, the terminal(-output) gives you a lot of useful information, both on the application as well as the desktop file. An example: if I run my application from the terminal, typing the command in the terminal, the application starts.

However, if there is something wrong, you can expect an output like:

Traceback (most recent call last):
  File "/home/jacob/Bureaublad/werkmap_2.0/uploaded_versions/2.1.2/32_en_ppa    /qle-2.1.2/code/qle_quicklisteditor", line 4044, in <module>
    MainWindow()
  File "/home/jacob/Bureaublad/werkmap_2.0/uploaded_versions/2.1.2/32_en_ppa   /qle-2.1.2/code/qle_quicklisteditor", line 51, in __init__
    self.load_sectons()
AttributeError: 'MainWindow' object has no attribute 'load_sectons'
jacob@Jacobwerkkamer:~/Bureaublad/werkmap_2.0/uploaded_versions/2.1.2/32_en_ppa   /qle-2.1.2/code$ 

which gives you a lot of usefull information, even the line in your application that causes the error. (I messed it up on purpose)

The same with the desktop file, just open a terminal in the directory of the .desktop file and drag it on to the terminal. If you for example remove the Exec= line from a .desktop file, the terminal will tell you it cannot find the command to execute.

To test if the application gives an error, just run what you put after theExec= string.

The terminal output is usually very specific and useful in bug reports, like here.

1
  • 3
    I know about how to use a terminal and how to troubleshoot a program launch in general. Assuming this approach, what I need to know is how to reproduce the conditions of a .desktop launch accurately in the terminal.
    – Kevin Reid
    Mar 20, 2014 at 18:41
1

For me, the problem was a missing Icon= line (which seems like a stupid requirement for a working launcher). My full .desktop file now looks like:

[Desktop Entry]
Name=LiClipse
Comment=Variant of Eclipse
Exec=/home/tsbertalan/bin/liclipse
Terminal=true
Type=Application
Icon=/home/tsbertalan/usr/liclipse/icon.xpm

Which isn't particularly robust to changes in user, but whatever.

1
  • Thanks! Icon seems to be required to run, although desktop-file-validate did not complain about it. Jul 18, 2022 at 13:18
1

This might help other people - this is the official spec of the desktop launcher files

The important section is : Recognized desktop entry keys - which shows you which values you need.

0

When I really can't figure it out, I:

cd ~/Desktop
ln -s /my/binary/thatIwanttorun mybinary

Then right click on the default icon that's created and point to a better graphic.

1
  • and there should be a <cr> after "cd ~/Desktop"
    – Tom
    Feb 9, 2019 at 21:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .