21

I am using Linux, and I would like to be able to programmatically open notebooks in a running Mathematica instance from the command line. Currently, doing something like

/opt/Wolfram/Mathematica/8.0/Executables/Mathematica foo.nb

launches a new kernel/frontend instance. Is it possible to re-use a running frontend for opening notebooks (short of enforcing single-instance behavior, for which I believe there is a command line option)?

Leo Alekseyev
  • 1,305
  • 1
  • 11
  • 11

1 Answers1

21

You can start Mathematica with :

/opt/Wolfram/Mathematica/8.0/Executables/Mathematica -sl &

and then open your notebook in the same session with :

/opt/Wolfram/Mathematica/8.0/Executables/Mathematica -sl foo.nb

From the man page Mathematica --help :

-sl (--singlelaunch): Open in an existing process, if possible.

b.gates.you.know.what
  • 20,103
  • 2
  • 43
  • 84
  • Yes, the -sl flag does the trick. Another instance of Mathematica can still be launched by omitting the flag; opening notebooks afterwards with the -sl flag will still be bringing them up in the first instance – Leo Alekseyev Oct 27 '12 at 20:19
  • 1
    It seems it's very important that the first instance is also started with -sl. – Szabolcs Jul 17 '15 at 08:51
  • Is there an easy way to change the shortcut so this is the default always – William Oct 15 '16 at 20:27
  • 2
    Its /usr/local/bin/Mathematica -sl in my version of ubuntu but yes it works. – William Oct 15 '16 at 20:43
  • @William, did you find a convenient way to make this the default. (I open files by double-clicking and don't want to have to have to use the command line). (I would also be very happy creating many instances if not for the fact that Mathematica only allows me to open two instances probably for some crazy license reason). – Kvothe Sep 21 '22 at 13:30
  • @Kvothe I no longer have Mathematica installed currently. It may make sense to ask another question considering this is only for the command line. – William Sep 21 '22 at 14:04
  • See https://mathematica.stackexchange.com/questions/273776/opening-a-notebook-in-an-existing-instance-by-double-clicking-the-file-linux for how to set this as the default way to open mathematica files using the file explorer. – Kvothe Sep 21 '22 at 15:39