0

I am attempting to debug javascript that runs inside Adobe indesign. The first executable line returns an "undefined is not an object"

if ( app.documents.length==0 ) { exit(); }

Could Adobe have moved the nested object "documents" to a higher level?

mattdevio
  • 2,319
  • 1
  • 14
  • 28
sumaafaizy
  • 21
  • 1
  • 3
  • 2
    Either `app` or `documents` is undefined. I don't know enough about the scripting environment to say which; if you can output debugging info, try `console.log(typeof app)` to see if you have a handle on the right `app` object. – nrabinowitz Nov 23 '15 at 18:01
  • 2
    You need to include more information. whats in app, what is documents, etc. maybe JSON.stringify(app) and include that in your question – Gabs00 Nov 23 '15 at 18:01

3 Answers3

1

Your code can be safe but to be effective make sure script is properly targeted. I.e. if your debug is processing from ESTK - choose a target application from left-up corner dropdownlist or place this line in code's very top:

#target indesign 
Cashmirek
  • 269
  • 1
  • 9
  • Possible targets are: aftereffects acrobat aftereffects audition ame bridge contribute devicecentral dreamweaver exman encore estoolkit fireworks flash illustrator indesign indesignserver incopy photoshop premierepro soundbooth http://estk.aenhancers.com/5%20-%20Interapplication%20Communication%20with%20Scripts/application-and-namespace-specifiers.html – Luc Bloom May 17 '18 at 13:36
1

Cashmirek is probably right. If you are running your script from inside ExtendScript ToolKit, you need to either type in the #target instruction or pick InDesign in the application list.

Loic
  • 2,173
  • 10
  • 13
-1

To be safe I would suggest, you use something like this:

if (app === undefined || app.documents === undefined || app.documents.length === 0) { 
    exit();
}

The exit()will be performed if app or app.documents or app.documents.length is undefined or app.documents.length is 0. It eliminates the exception problem, because Javascript will stop evaluating the conditions, after one found 'true'.

Be sure to use === instead of == to ensure type comparison.

Hope that helps

Guido Kitzing
  • 892
  • 5
  • 14