MATLAB Community

MATLAB, community & more

Starting MATLAB from the Mac OS X Finder 5

Posted by Michael Katz,

I’d like to welcome back guest blogger Ken Atwell for his second in a two part series of accessing MATLAB from the Macintosh OS X environment. This week he writes about opening a MATLAB file from the Finder.

MATLAB source files have the .m extension and the Finder should have an association between MATLAB and files with a “.m” extension. However, if you try to open a MATLAB source file by double-clicking in the Finder, you may get one of these unexpected behaviors:

  1. Rather than starting MATLAB, you may get a report of a crash and an offer to reopen the application. Should you choose to reopen, you will again get a crash. This is happening because MATLAB, not a required starter application, is being invoked by the Finder. Refer to my previous post for a discussion of the MATLAB starter app and the reasons why this crash happens.
  2. Rather than starting MATLAB, Xcode (Apple’s software development environment) may start. In an unfortunate coincidence, the .m extension is also used by Xcode for Objective-C files (with “m” indicating a file containing Objective-C methods). If you have Xcode installed on your Mac, it is likely that double-clicking a MATLAB source file will start Xcode instead of MATLAB.

Both of these problems can be addressed with the same procedure: To open a MATLAB source file from the Finder on a one-off basis, you can Control-click (or right-click) the file and use the Open With menu. On Snow Leopard, you will see two MATLAB choices, one called “MATLAB_R2009b” (the exact choice depends on the version of MATLAB you have installed) and the other one simply “MATLAB” (Figure 1). Choose “MATLAB_R2009b” (the starter application) and not “MATLAB”. Choosing “MATLAB” will result in a crash as discussed above.

Figure 1: Using “Open With” to launch MATLAB instead of Xcode
Use Open With to launch MATLAB instead of Xcode

Suppose you wish to launch MATLAB every time you double-click any file with the .m file extension? The Mac OS X Finder allows you to change the default double-click behavior:

  1. Control-click any MATLAB source file (with a “.m” extension) and then select Get Info.
  2. In the Info window, expand the Open With section and select “MATLAB_R2009b”… again, not “MATLAB” (Figure 2).
  3. Click Change All… and then confirm that all files with the .m extension should be opened with “MATLAB_R2009b”.
Figure 2: Changing the default Open behavior for MATLAB source files
Change default Open behavior for *.m files

MATLAB should now start without issue whenever you double-click a MATLAB source file in the Finder.

Have you figured out any other OS X shortcuts or tricks that have simplified your workflow? Chime in below!


Comments are closed.

5 CommentsOldest to Newest

the cyclist replied on : 1 of 5

After downloading a new version of MATLAB next time, I wonder if I will remember to change my “Open with” setting for MATLAB source files.

mrhill replied on : 2 of 5

Desired behavior: double click a .m file in the Finder, it open matlab and opens the file in the editor.

Your advice doesn’t work for me. If matlab 2009b is not running, it will start. After it starts the file I double clicked does not open in the editor. If matlab 2009b is already running, it becomes the foreground app (after a delay caused by the starter-app opening), but the file I double clicked does not open in the editor.

It doesn’t seem like this should be difficult, so I’d love some help.

Peter McHale replied on : 3 of 5

I have the same problem as mrhill. I’m running Matlab R2009b on an imac. A solution would be greatly appreciated. Thanks.

Mike replied on : 4 of 5

@mrhill, @Peter,

I will take a look into it. (To get dedicated resources for diagnosing the issue and the ability to track it – contact tech support).

Mike replied on : 5 of 5

@mrhill, @Peter,

I checked in with our developer, and this functionality in MATLAB is currently broken on Mac OS X 10.6 Snow Leopard. The workaround is to start MATLAB first, and then open files from the Finder. Alternatively, you can drag the file icon to the StartMATLAB icon in the Dock or in the Application folder.