Ubuntu – My custom .desktop file appears in Dash as a text file

desktopMATLABunity-dash

I recently installed MATLAB on my computer. I found that while I could easily start MATLAB from the terminal, there was no executable file I could double click on to run it. So I created a Bash script to run MATLAB and then created a .desktop file and saved it in /usr/share/applications/. Here's the content of that .desktop file:

[Desktop Entry]
Type=Application
Name=MATLAB
Hidden=false
Exec=Desktop/Programs/scripts/runMatlab.sh
Icon=/usr/share/icons/matlabIcon.jpg
Categories=Application;

If I look inside /usr/share/applications/, I indeed see an executable file with the name MATLAB and the appropriate icon, and if I double click on it MATLAB will run just fine. However, if I type MATLAB into Dash, matlab.desktop appears as a text file. It doesn't have the correct name (MATLAB) or correct icon, and if I click on it Gedit will open instead of the file being executed.

How can I fix this?

I am using Ubuntu 14.04 by the way.

Best Answer

If you take a good look in Dash, you will find out that matlab.desktop does not appear as an application, but the file matlab.desktop appears in search, or recently used, since you obviously edited it.

The error

The reason is that Dash does not see it as a valid .desktop file for (at least) the following reason:

  • You should not use relative paths in a .desktop file (Desktop/Programs/scripts/runMatlab.sh is relative), but absolute paths.

Other possible reasons could be an invalid icon path or the fact that you call the script without the preceding sh (if the script is not executable, but given the other information in your question, that seems not to be the case).

Notes

  • Another thing is that if you store the script on what appears to be a local directory, you should not store the .desktop file in /usr/share/applications, but in ~/.local/share/applications.

  • There is no need to make a .desktop file executable if you run it from Dash or the Launcher. Most launchers in either /usr/share/applications or ~/.local/share/applications are not. Only if you locate it on- and run it from your Desktop.

Related Question