Photoshop.app Properties Returning as null Proxies

The type of documents and layers (and the like) is different from apiLevel 1 and 2.

  • apiLevel 1: app.documents => Array
  • apiLevel 2: app.documents => Proxy

Things like layers and documents are not Arrays in API Level 2 – they are iterable proxies that expose similar methods, but console.log is clueing you in to the fact that these are not derived from Array.

This is for performance reasons (especially due to the underlying need to use batchPlay): Ps doesn’t need to construct an object for a given index until you ask for it. This lets you avoid the cost of creating objects for the first 10 items when you ask for the eleventh, for example.

For cases where you want to treat these properties like an array, you can use Array.from or spread to convert the array-like to an Array:

console.log(app.documents); // Proxy {}
const documentsArray = Array.from(app.documents); // also [...app.documents] would work
console.log(documentsArray); // (2) [Document, Document]

Note that when the console logs out the Proxy, it’s not listing out the elements, but you shouldn’t take that as the property being empty.

4 Likes