This post is part of the CEP Mega Guide series.
And so we reach the longest and most detailed part of the guide – how to actually make Adobe tools do stuff from an HTML panel. Taking a deep breath, and keeping the feet shoulder-width apart, here we go:
In this series I’ll refer to the two JS engines as the panel VM and the tool VM. Architecturally, things look like this:
As shown, scripts in the tool VM can directly call internal functionality (like opening a new document). To do such things from the panel VM you pass code to the tool VM.
Passing script to the Tool VM
var js = "alert('Hello from the tool VM')";
var cs = new CSInterface();
Note the different quotes used to wrap that command into a string literal. You can also get callbacks from the tool VM, if you call evalScript and pass in a function. In my extension work I found it useful to make a helper function that passes a script over to the tool VM, and writes the result to the console, thus: