The basic idea is to set $DisplayFunction or $Post.
I have the following code in my tool bag:
BeginPackage["CommandLineUtilities`Display`"];
WolframPlayer;
Begin["Private"];
$TemporaryOutput = FileNameJoin@{$TemporaryDirectory, "WolframKernelOutput"};
If[!DirectoryQ@#, CreateDirectory@#] &@$TemporaryOutput;
WriteToShell[str_] := (
If[Head@$ShellProcess =!= ProcessObject, $ShellProcess = StartProcess@$SystemShell];
WriteLine[$ShellProcess, str];
str
)
MakeNotebook[box_] := Notebook[{Cell@BoxData@box}, WindowSize -> All]
WolframPlayer[expr_, box_] := (
$WolframPlayerProcess = If[# === {}, StartProcess@"WolframPlayer", None] &@SystemProcesses@"WolframPlayer";
StringJoin[
"WolframPlayer ",
Export[FileNameJoin@{$TemporaryOutput, CreateUUID["CDFOutput-"]<>".cdf"}, MakeNotebook@box, "CDF"]
] //WriteToShell;
ExportString[OutputForm@expr, "Text"]
)
$Epilog := (
KillProcess/@{$ShellProcess, $WolframPlayerProcess};
Quiet@DeleteFile@FileNames[__, $TemporaryOutput];
If[FindFile["end`"] =!= $Failed, << "end`"] (* Original definition. You can read it with OwnValues. *)
)
End[];
EndPackage[];
($DisplayFunction = WolframPlayer[#, ToBoxes@#]&;)
$Post = With[{box = ToBoxes@#},
If[FreeQ[DynamicBox|DynamicModuleBox|GraphicsBox|Graphics3DBox]@box,
#,
WolframPlayer[#, box]
]
]&;
This calls WolframPlayer. For non-interactive contents, you can simply export as PNG and use another picture viewer.
Another way to do this is JavaGraphics`. It costs a lot of time on its first loading, so that it may be inconvenient when you frequently restart wolfram kernel sessions.
SystemOpen[File["C:\\test.pdf"]]runs the acrobat reader and opens this file on my machine. I am on Windows though. Try to see if you canExporta graphic to a certain location on disk. Then use the full path to the file and it should open with the registered application on your OS. This is as much as I can help you since I am not on a Mac. I am using Mathematica not the Wolfram Engine. – Syed Nov 14 '21 at 21:30https://github.com/WolframResearch/WolframLanguageForJupyter
– Pavel Perikov Nov 15 '21 at 09:00