How to update a textLayer's text?

  • manifest.json
{
  // ...
  "manifestVersion": 4,
  "host": [
    {
      "app": "PS",
      "minVersion": "23.00",
      "apiVersion": 2
    }
  ],
// ...
}
  • script
    I have two textLayers: A and B.
    When I click to select B and pass A to this function, B is changed , why not A ?
    How to speicify the layer?
const updateTextLayerText = async (layer, text) => {
  console.log(layer.name, layer._id, text);

  return await require("photoshop").core.executeAsModal(async () => {
    const ret = await require("photoshop").action.batchPlay(
      [
        {
          "_obj": "select",
          "_target": [
            {
              "_name": "1-999",
              "_enum": "ordinal",
              "_ref": "textLayer",
              "_value": "targetEnum",
              "_id": layer._id,
            }],
          "layerID": [layer._id],
          "makeVisible": false
        },
        {
          "_obj": "set",
          "_target": [
            {
              "_name": "1-999",
              "_enum": "ordinal",
              "_ref": "textLayer",
              "_value": "targetEnum",
              "_id": layer._id,
            }
          ],
          "layerID": [layer._id],
          "to": {
            "_obj": "textLayer",
            "textKey": text,
          },
        }
      ], { "synchronousExecution": true, });
    console.log(ret);
    return ret;
  }, { commandName: "Update Text Layer" });
};