9

My only prior experience with #targetengine is when I've used #targetengine "session"; to turn a dialog into a palette when scripting in InDesign. But as I'm trying to figure out how to script a menu, I'm starting to see it pop up being used in other ways and using a term (target?) other than session.

Adobe likes to assume that everyone who wants to script is an experienced programmer sometimes, so I haven't found a clear explanation as to what this is.

So, when I use #targetengine, what am I doing? Can I use any term other than "session"? Some searches suggested this feature has to do with global variables; is that the case? If so, how can I clear them out without restarting InDesign? Is this a JavaScript thing or an ExtendScript/InDesign feature?

Brendan
  • 868
  • 1
  • 16
  • 38
  • 1
    `everyone who wants to script is a programmer` Umm... However, Adobe's "Javascript" crud is DOA. Meh. – Jared Farrish Dec 27 '12 at 21:46
  • I'm a graphic designer who codes when I need to, not a programmer, so a lot of times I feel like there are assumptions that they make that I just don't know. – Brendan Dec 27 '12 at 21:48
  • I would suggest picking up a book on JavaScript, if that is what you want/need to learn. – Brad Dec 27 '12 at 21:50
  • @Brad, I'm somewhat familiar with JavaScript; I've made web pages for years and have made numerous scripts in InDesign. I'm just trying to expand my skills here and got hung up on this point. JS is really well-documented online usually but because fewer people script for ID, some features are tough to learn about by searching online. Which JavaScript book would help me learn more about `#targetengine`? – Brendan Dec 27 '12 at 21:53
  • 2
    Have you read [this](http://incom.org/post/89818), and [here](http://stackoverflow.com/questions/11405987/indesign-cs5-script-why-is-targetengine-not-working-correctly)? It appears to be a flag to the Javascript engine to keep that variable in the quotes during the entire duration of the time you have InDesign open. It's like a "session"-level value. – Jared Farrish Dec 27 '12 at 21:55
  • @Brendan, Other than the InDesign documentation, I'm not sure. Hopefully someone will come along and have the answer for you. – Brad Dec 27 '12 at 21:55
  • Here is the [InDesign Javascript Reference (PDF)](http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/products/indesign/pdfs/InDesignCS5_ScriptingGuide_JS.pdf). Do a file search for `targetengine` and there's several entries; it's apparently a powerful feature for InDesign, since it allows you to keep code up and running after it would normally quit (as in, as soon as it gets to the end). – Jared Farrish Dec 27 '12 at 22:01

2 Answers2

31

#targetengine is specific to the Adobe scripting in InDesign, PhotoShop, Illustrator etc. - it is not a general Javascript feature.

It specifies how to handle all the global 'stuff' - not only variables but also function declarations and any other change to the global status.

If you use the default 'main' engine all the globals disappear as soon as the script completes. If you use the 'session' engine all the globals are preserved as long as the host application keeps running. This means that if you run the script:

#targetengine "session"

var test = "test";

and later run the script:

#targetengine "session"

alert(test);

you get a message box showing test instead than giving an error

Besides the two standard 'main' and 'session' engines you can create your own ones, with arbitrary names - so if you run the script

#targetengine "mine"

var test = "another test";

and then run

#targetengine "mine"

alert(test);

you get a message box showing another test, but if you run again

#targetengine "session"

alert(test);

you still get test: there are two different 'test' global variables, one in the 'session' engine and one in the (newly created) 'mine' one.

MiMo
  • 11,793
  • 1
  • 33
  • 48
  • 1
    I am afraid Photoshop has no support for `#targetengine`, everything runs in the same engine – alerting `test` in the `"main"` engine without declaring it throws an error, otherwise `#targetengine` is just ignored. The JavaScript Tools Guide CC itself says it's an InDesign and Illustrator only feature, but I'm told also PremierePro has it. – Davide Barranca Jul 20 '19 at 06:20
  • I correct my previous statement: InDesign and Illustrator *only* do have `#targetengine` support, PremierePro does not. – Davide Barranca Aug 02 '19 at 15:29
2

This discussion was brought up in a Slack channel I monitor. One long-time developer said the following (cleaned up a bit for clarity):

As far as I know //@targetengine only works on InDesign (probably including InCopy) and Illustrator.

On InDesign it works properly and on Illustrator it does not. Nevertheless other apps as far as I know all have the ability to use targetengines with C++ and that’s what CEP does with each CEP [extension?] having its own isolated engine.

There are at least 3 types of engine.

  1. main engines, in InDesign it’s a temp engine that forgets everything after completing a scripts execution.

  2. Public Private engines like session that remember and are active after script execution and good for event listeners. These and main can be identified using $.engineName and found on ESTK / vsCode

  3. Private Private $.engineName will show "" can only be created with C++ that what most of the apps use and CEP uses except for InDesign where CEP uses Public Private engines which can be chosen.

He thinks there's also a 4th type he's forgetten.

Erin Finnegan
  • 498
  • 3
  • 7