# Mathematica script, called from Windows task scheduler, does not export graphics

When I run the following script from command line,

Needs["JLink"];
ConnectToFrontEnd[];
resultChart = UseFrontEnd[JuliaSetPlot[0.365 - 0.37 I]];
UseFrontEnd[Export["test.png", resultChart]];
CloseFrontEnd[];


the graphic file gets written out fine. In fact, the calls to ConnectToFrontEnd, UseFrontEnd, CloseFrontEnd are not even necessary.

However, if I call this script from Windows task scheduler, the function ConnectToFrontEnd returns True, but then an error is returned:

Rasterize::type : Notebook[ -- omitted --] cannot be rasterized.


I am aware of these two, similar questions, however I do not know what to do now here.

• There is the builtin UsingFrontEnd, so you don't need UseFrontEnd from J/Link. But neither JuliaSetPlot, nor Export need it. (Export should make use of it internally). I don't know why it doesn't work for you, but what happens if you drop the unneeded parts? Dec 8 '16 at 17:43
• In case you suspect front end trouble, to test if a front end is available, check that Head@UsingFrontEnd[$FrontEnd] === FrontEndObject Dec 8 '16 at 17:46 • I haven't personally tried this before, so YMMV... I would switch to UsingFrontEnd and then ensure that when the task scheduler runs your script it has access to a desktop session. Kinda like on X, the Windows FE requires this to do just about everything... Dec 8 '16 at 19:55 • Thank you for your comments. Head@UsingFrontEnd[$FrontEnd]===FrontEndObject returns True. Switching to UsingFrontEnd did not help. Running the task with the option checked "only run if user is logged on" (which I interpret as making sure that there is access to a desktop session) does work! I am not an admin, so I am not sure if that is an option in the long run. Dec 9 '16 at 10:25

resultChart = JuliaSetPlot[0.365 - 0.37 I];
`