MATLAB: How to bring a figure into focus programmatically in MATLAB on a Mac OS X machine

10.3automatic;clickfigurefocusginputmacMATLABmouseosxplotswitchwindow

When I create a new figure, the focus is still on the MATLAB application even though the figure window is on top. To activate any buttons or interact with the figure in any way, I have to click on it once just to gain focus and then click on it again to interact with it. Is there a command to give the window focus without having to click on it?
For example, the following code generates a figure window in the foreground, but it doesn't gain focus until it is clicked:
plot(1:10)

Best Answer

This enhancement has been incorporated in Release 14 Service Pack 3 (R14SP3). For previous product releases, read below for any possible workarounds:
The focus can be changed programmatically using Apple Script. Create a new file called "raiseX11.as" which contains the following three lines:
tell application "X11"
activate
end tell
To execute the script file, use the following command at the MATLAB prompt:
!osascript raiseX11.as
For example, to create a plot and then give it focus, enter the following commands:
plot(1:10)
!osascript raiseX11.as