1

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.

  • 1
    Have you set the executable flag? – Byte Commander Jan 27 '15 at 16:10
  • @ByteCommander I'm sorry, but I don't know what an executable flag is. – Alessandro Power Jan 27 '15 at 16:26
  • Sorry, I meant if you added the execution permission to your matlab.desktop by running chmod +x matlab.desktop? Same procedure as for .sh shell scripts. – Byte Commander Jan 27 '15 at 16:30
  • @ByteCommander Yes, I did. – Alessandro Power Jan 27 '15 at 16:36
  • Would you run desktop-file-validate matlab.desktop? It should show whether there are any errors in the .desktop file. If there is no output, the file is fine. – Byte Commander Jan 27 '15 at 16:44
1

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.

| improve this answer | |
1

First of all, move the .desktop file to /usr/share/applications/ (global launchers, needs root permission to move file) or to ~/.local/share/applications/ (only for the current user).*
EDIT: When you run desktop-file-install, this is not necessary as it automatically copies the file to /usr/share/applications/

Then, after checking your .desktop file for errors with desktop-file-install filename.desktop (no output means no errors, but even some warnings may not prevent the launcher from working),
you add it to the Unity dash by running sudo desktop-file-install filename.desktop (EDIT: root privileges required to access /usr/share/applications/ where global launchers are stored). Please note that this command might add some lines to the original .desktop file.

I hope this solved your problem. Greetings!
(Source: https://help.ubuntu.com/community/UnityLaunchersAndDesktopFiles)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.