Ubuntu – How to make a Matlab launcher for Unity

desktopMATLAB

I'm trying to install a Matlab R2011a launcher for Unity in Ubuntu 12.04. I've tried this guide (although I know it's for 11.10 and mentions that even 11.10 is an unsupported OS for Matlab R2011a) but without any satisfactory solution.

This is my launcher file, /usr/share/applications/matlab.desktop:

#!/usr/bin/env xdg-open
[Desktop Entry]
Type=Application
Icon=/usr/share/icons/matlab.png
Name=MATLAB R2011a
Comment=Start MATLAB - The Language of Technical Computing
Exec=matlab -desktop
Categories=Development;

I open the dash panel and search for "matlab". This launcher is found among applications. I click it, and Matlab's splash screen shows up, but when it disappears the program doesn't start. (I've verified with htop that no matlab-processes are running in the background either.)

If I add

Terminal=true

to the launcher file, the program starts OK, and opens a terminal as well as Matlab. However, both the terminal and Matlab itself show up in the Launcher area, with the Matlab icon, so it looks like I have two Matlab instances running when really it's only one. (Actually, they show up as two different programs, and not just two instances of the same – the icons are independent, not grouped together.)

This is definitely not optimal. I had hoped to create a launcher I can lock to the launcher area, and then that same icon will be the icon for the active Matlab instance when the program is running.

How do I create a launcher for Matlab that works as expected?

Update: I was apparently a bit unclear on my symptoms, I'll try to clarify a little.
I've also tried some suggestions from the answers, and further investigated what happens. My current setup (a launcher file with Terminal=true and Exec=matlab -desktop -nosplash &) renders the following behavior:

  1. I open Dash by pressing the Windows key on my laptop, and search for "matlab". It finds the launcher named "MATLAB R2011a". I click it.
  2. A terminal window opens, using the icon I referred to in the launcher file. Almost immediately, MATLAB's splash screen also opens, using the same icon (and thus being grouped with the terminal window in the launcher).
  3. The splash screen disappears and, so does one of the icons in the launcher. The MATLAB desktop environment opens, using a different version of the icon which is displayed next to the icon for the terminal window (not grouped with it).

I can lock the terminal window's icon to the launcher and successfully start MATLAB by clicking it, but it doesn't feel optimal that I start the program with one icon, and switch to it with another. I've also tried the following:

  • Exec without the ampersand & in the launcher command, but it didn't make a difference.
  • Executing matlab -nosplash manually from a terminal still shows the splash screen. (What, then, does the nosplash option really do?)

Best Answer

Garrett's answer almost works for me, but instead I have to use

StartupWMClass=sun-awt-X11-XFramePeer

This still gives an extra launcher icon while the splashscreen is visible (because the WM_CLASS of the spashscreen is just "MATLAB"), but then the window gets properly grouped under the launcher.

New instances of Matlab (started by terminal, or Synapse, or from another tty with export DISPLAY=:0) also get grouped under this launcher, and the launcher's quit option kills all of them.

I found this WM_CLASS value by using

$ xprop WM_CLASS

and then clicking on the Matlab window, a command I got from Superuser.

To prevent the temporary extra launcher icon, you can also add the -nosplash flag after the -desktop one.

So, my ~/.local/share/applications/MATLAB.desktop looks like this:

[Desktop Entry]
Version=1.0
Type=Application
Icon=matlab
Name=Matlab
Comment=Start MATLAB - The Language of Technical Computing
Exec=matlab -desktop -nosplash
Terminal=false
Categories=Development;
StartupNotify=true
StartupWMClass=sun-awt-X11-XFramePeer
X-Ayatana-Desktop-Shortcuts=New_Window;

Name[en_US]=MATLAB

[New_Window Shortcut Group]
Name=start a new MATLAB instance
Exec=matlab -desktop

This is on Ubuntu 12.10, with Matlab R2012b