How to check if image is 8 bit or 16 bit To Do Somthing?

welcome everybody
What is wrong with the code I used
It does not work
I want it to fulfill the condition.

THE CODE:

const myDepth = async () => {
  const result = await batchPlay(
    [{
      "_obj": "get",
      "_target": [{
          "_property": "depth"
        },
        {
          "_ref": "document",
          "_enum": "ordinal",
          "_value": "targetEnum"
        }
      ],
      "_options": {
        "dialogOptions": "dontDisplay"
      }
    }], {
      "synchronousExecution": false,
      "modalBehavior": "fail"
    });

  var documentDepth = result[0].depth;
  app.showAlert(`The Document is in ${documentDepth.toString()} bits`);
}

//The condition....
if (myDepth() === 16) {
    // logic for 16 bit
} else {
    // logic for 8 bit or other
}

Regards
Mohamed Fathy

you don’t need batchPlay for this.

you can use

let bitDepth = app.activeDocument.bitsPerChannel
// outputs a string : bitDepth8, bitDepth16 or bitDepth32

if you prefer using batchPlay:

const {batchPlay} = require("photoshop").action;

let command = [{ _obj: "get", _target: [{ _property: "depth" }, { _ref: "document",_enum: "ordinal",_value: "targetEnum" }]}]
let bitDepth  = (await batchPlay(command, {}))?.[0]?.depth;
// outputs a number: 8, 16 or 32
1 Like

Thank you my friend, you are my superhero :man_lifting_weights:.
I hope you have a good day
This is really what I want.

Regards :pray:
Mohamed Fathy…