Once again, I’d like to welcome guest blogger Ken Atwell. Ken is a product manager for MATLAB who spends much of his time focusing on platform support. His past blog posts about the release of Snow Leopard and Windows 7 generated quite a bit of interest and discussion, so Ken will be occasionally blogging about platform considerations when using MATLAB. This week, Ken writes about the relationship between MATLAB and the Mac OS X Dock.
The Dock is OS X’s mechanism for giving users access to frequently-used applications. There are two primary ways to get an application into the Dock. However, in the case of MATLAB, only one of these will work:
- The Working Way. Go to your Applications folder and drag the MATLAB application (it will be called “MATLAB_R2009b.app” or similar, depending on the version of MATLAB you have installed) to the Dock (Figure 1). The icon will be the familiar L-shaped membrane, but with an up-arrow overlay.
- The Not Working Way. Start MATLAB from Applications, and then add MATLAB to the Dock using click-and-hold->Options->Keep in the Dock. Unfortunately, starting MATLAB from a Dock icon created this way will results in a MATLAB crash at start-up. If you have created a Dock icon in this manner, remove it and recreate it using the “working” method above.
What is going on?! The reason for this behavior lies in MATLAB’s somewhat complex start-up sequence. MATLAB is started through a starter application that is responsible for starting the “real” MATLAB. In the first case, the starter application is added to the Dock (which is why the icon includes an up-arrow). In the second case, the “real” MATLAB is added to the Dock, and starting the “real” MATLAB directly from the Dock (or the Finder, for that matter) results in a crash. We expect to correct this in a future version of MATLAB.
With the starter application in the Dock, MATLAB should start normally and you will get a second MATLAB icon (the running, “real” MATLAB) in the Dock (Figure 2). Again, we acknowledge this is could be improved; there should only be one icon.
Once MATLAB is running, you can use either of these icons to bring MATLAB into focus. Given this behavior, it may be unclear how you can start a second instance of MATLAB. You can do this from a Terminal window as follows (replacing “R2009b” with your version of MATLAB as required):
- Go to the Utilities folder inside your Application folder.
- Open Terminal.
- Type: /Applications/MATLAB_R2009b.app/bin/matlab
- Press Return.
Note that closing the terminal window will also close the second MATLAB.
Be aware that changing any application setting that is saved on disk, such as your Preferences, Desktop layout, and MATLAB path, will not take effect across other already-running instances of MATLAB, and the exact state that will be stored to disk can be difficult to predict. For this reason, I recommend against wholesale changes to your MATLAB environment when running multiple instances of MATLAB.
I hope this information will be helpful to Mac users who would like to launch MATLAB directly from the Dock. If you have any other Dock tricks you’d like to share with fellow MATLAB users, please chime in below!
17 CommentsOldest to Newest
Issues like this may seem like small things, but in my opinion they keep Matlab from being a first-class citizen on the Mac. I often click on the icon of a running app to bring the windows of that app to the front, and I always go to the wrong icon with Matlab (and sometimes accidentally start a second instance).
It would also be nice if Matlab didn’t leave X11 running when it quits.
Since using Cocoa seems the only way to develop for iPad, which is clearly the future of mobile computing for OS X, maybe we’ll get lucky and get a Cocoa version of Matlab someday.
Thanks for the feedback. We made this post because we are aware of the limitations and pains, and we hope to over time get MATLAB to the point where the user experience on the Mac is top-notch.
The A4 processor running in the iPad and the iPhone OS is not sufficient run full MATLAB, but I’m sure we’ll do something interesting mobile-wise. Unfortunately there are enough differences between Cocoa and Cocoa Touch that if even we completely rewrote the MATLAB UI in Cocoa, we’d have to completely rewrite it again again for the iPhone/iPad (different interaction models notwithstanding).
The future of mobile computing sure is looking interesting these days, though.
Your description of the dock workaround includes Terminal commands, because Finder can’t see past MATLAB_R2009B.app, as has been the case for a few versions now. I assume that this problem is related to the docking issue. Could MATLAB not appear more like Office 2008, since it’s already organized similarly (i.e., clearly folders rather than one big application file with hidden folders)? I shudder to think how many Mac MATLAB users are unfamiliar with Terminal, but there are probably many, and life could be easier for them.
I agree with the first poster. Their description of how they prefer to switch primary applications, a problem I don’t have because I use Command-tab, made me realize how well MATLAB has trained me to accept its (increasingly milder) Mac eccentricities, such as X11 behavior. ;)
Part of the problem is just general unfamiliarity with productivity enhancing keyboard shortcuts. I couldn’t count how many people whose eyes have widened when I showed them Command-tab. My own MATLAB experience improved a lot when someone showed me Command-tilde to switch between an application’s windows. I often find that folks who don’t know about that one have dreadfully complicated and honestly non-functional Matlab desktops…of which the most frustrating part is a tiny figure dock!
This might not be directly relevant to the topic of the blog, but since we are talking about running Matlab on Mac OS, I though I’d this:
The behavior of Matlab windows are not consistent in Mac OS X, especially, when using Simulink. In R2009b, the Simulink models open in X-windows, but if I click on a block to open the parameters dialog window, it is a Matlab window (AFAIK, a Java window, made to look like a COCOA one) and when I press OK or press Enter on my keyboard the focus transfers to the last window of Matlab instead of the Simulink model. This is such nuisance when building a large model in Simulink as every time after changing a parameter you have to click or command-tab back to the Simulink model window.
Is there a fix for this?
I prefer to open Matlab via the Terminal, so that I have access to all environment variables (especially the full PATH). To still be able to use the dock, I have written the apple script below (there may be more efficient ways to do this, but I’m still a beginner).
Simply open the AppleScript editor, paste the text there, and save as an application (e.g. startMatlab2010a). Then you can drag it onto the dock, and double click as usual.
Note that you can go and steal the Matlab icon from Matlab.app by copy-pasting the icon on the top left of the window that is opened by right-clicking on the application and choosing ‘get info’.
tell application “System Events” to set processlist to get name of every process
tell application “Terminal”
if processlist contains “Terminal” then
do script “/Applications/MATLAB_R2010a.app/bin/matlab &”
do script “/Applications/MATLAB_R2010a.app/bin/matlab &” in front window
I am not a Mac user, but I came across this article explaining how to hide a useless Matlab icon from the Dock bar: http://www.macosxhints.com/article.php?story=20080212162806562
I’m not sure it solves the issue mentioned above, but it seemed relevant so I wanted to share.
I think the weird dock behaviour is certainly not a major issue. The fact that Guide UIs working cross-platform (i.e. built on Windows) are often totally unusable on OS X is. It seems like a minor fix, adjust the widget dimensions to encompass the cocoa style padding etc, but has been broken like this for years. Ken Atwell had mentioned there were bugs logged about this before 2009b was released (comment in the snow leopard thread), so i’m really hoping 2010a contains a fix for this severe bug.
Hooman (@4): If you are interested in chatting with me concerning Simulink, please ping me at ken.atwellNOSPAM@mathworks.com
Jonas, Yair (@5, @6): Thanks for adding to the discussion with your own finding!
Ian (@7): I think it was the *other* Ken :) that responded on the GUIDE issues. If you are willing to chat with me, drop me an email (ken.atwellNOSPAM@mathworks.com).
about the GUIDE issues for cross-platform GUIs… I have been using GUIDE back and forth between Mac, Windows and Linux for several years. I have found that I need to set the units for all of the controls, boxes, panels, (everything!) to pixels in order to make sure it all works. Also, the buttons need to be padded on a PC to account for the curved edges on a mac. I think it needs to be set to pixels due to the difference in DPI settings between the OSs. (I am not positive about this, but it makes sense with respect to the behavior I see)
I noticed that if I run a matlab script via os x terminal, once it is finished I can not see what I am typing anymore…
for example, I use this command:
matlab -nodesktop -nosplash -r "startup;Transform_EU_WriteDB_DayMth('M');quit"
once control is back to the shell, i have to blindly type exit to close the terminal
That is not the standard experience. There a lot of things that can be going on. You should contact tech support: http://www.mathworks.com/support/service_requests/contact_support.do. Before you do so, know the answer to this question: “does this behavior exist if you just do
matlab -nodesktop -nosplash -r quit
or is it only when running your script?”
Amazing that with the number of academics using MacOS X out there, Matlab’s GUI is still such a horrendous piece of crap on MacOS X. When will you finally put your act together and stop relying on X11? It isn’t even as if Matlab’s GUI was that complex to start with… Just rewrite it from scratch using Cocoa, rather than trying to cut corners by making a bad port.
Ouch! There’s not much I can right now, other than if it were that easy we would have done it by now. We’re aware of the pain and we’re working on it. We’ll have something nice to show you soon, but I can’t give any more details.
I stumbled on this post trying to look at ways to set the DYLD_LIBRARY_PATH and figure out a way so that MATLAB paths are same as those seen by Terminal.
My solution was to fix Info.Plist file in /Applications/MATLAB_R2009b.app/Contents, by adding the LSEnvironment key with a subkey DYLD_LIBRARY_PATH that is add the following lines
key>LSEnvironment /key> dict> key> DYLD_LIBRARY_PATH /key> string> bla bla /string> /dict>
/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister -v -f /Applications/MATLAB_R2009b.app/
so that OS X knows that Info.Plist has been updated.
Alternatively, environment variables can also be set in ~/.MacOSX/environment.plist.
@Martin and @Mike,
I totally agree with Martin on this one, it has been years since MATLAB has been available on Mac and the port is crappy at best of times. Most of the functionality expected from a OS X applications is not available in the MATLAB.
I hope that a native GUI for Mac is available soon.
How does one specify startup options such as -nosplash
when launching Matlab_R2009b from the Dock on a Mac OSX 10.6?
Not in a straightforward manner, you can use Automator to run some applescript that fires off the terminal commands.
this trick also works on Mac OS X Lion