2

I want to spawn a secondary matlab session to run a script programatically straight from the primary session.

I found out this may be possible using osascript as follows:

eval('!osascript -e ''tell application "Terminal"'' -e ''activate'' -e ''do script "matlab -nodesktop -nosplash -r \"myScript.m\""'' -e ''end tell''')

After running the script, a terminal window running the secondary Matlab session successfully opens but I get this error message in that window: "Undefined variable "myScript" or function "myScript.m".

I have tried a few things, including creating the secondary session first

eval('!osascript -e ''tell application "Terminal"'' -e ''activate'' -e ''do script "matlab -nodesktop -nosplash"'' -e ''end tell''')

followed by an attempt to pass the script to the secondary session using a separate osascript statement , e.g.:

eval('!osascript -e ''tell application "matlab"'' -e ''do script "myScript.m"'' -e ''end tell''')

but I get the error: "65:71: syntax error: Expected end of line but found âscriptâ. (-2741)"

I can run the script from the secondary Matlab session in the terminal window with no problem.

How can I run the script straight from the primary session? More broadly, how can I pass commands back and forth between the primary and secondary sessions using osascript.

Many thanks for any help.

JFD
  • 21
  • 1

0 Answers0