I am trying to write a wolframscript script to produce PDF versions of notebooks. I understand that to do this, I have to open the notebook, and only a frontend can open a notebook. However, depending on exactly how I try, I either get an immediate return (having taken no action) or a message like:
FrontEndObject::notavail: A front end is not available; certain operations require a front end.
I can run other scripts successfully, just none using notebooks. I can run the interpreter from the command line, just not accessing notebooks.
I have tried various approaches as described in
https://superuser.com/questions/381807/convert-mathematica-to-pdf-via-command-line -- and -- generating pdf using UseFrontEnd -- and -- UseFrontEnd is not working the same in version 10.4
These include:
- Using JLink
- Using UseFrontEnd
- Using UsingFrontEnd
- Running /Applications/Mathematica.app/Contents/MacOS/MathKernel directly
- Running wolframscript either with -script or not
- Having a shebang line #!/usr/bin/env wolframscript -print all or not
- Setting $FrontEndLaunchCommand and evaluating ConnectToFrontEnd[]
- Export or NotebookPrint
Here is the simplest case that I think should work in file bar.wls:
#!/usr/bin/env wolframscript -print all
notebook = UseFrontEnd@NotebookOpen["appendices.nb"];
UseFrontEnd@NotebookPrint[notebook, "print.pdf"];
invoked with "wolframscript bar.wls".
One interesting observation is that regardless of what I try Print[$BatchInput] always results in "False".
I am running Mathematica 11 on a MacBook.
I would appreciate insights and workarounds.