# Select duplicate rename export layer as PNG not exporting images

**URL:** <https://forums.creativeclouddeveloper.com/t/select-duplicate-rename-export-layer-as-png-not-exporting-images/5902>\
**Category:** UXP Plugin API\
**Tags:** export, filesystem, uxp, javascript, batch-play\
**Created:** [February 22, 2023, 9:04am UTC](https://forums.creativeclouddeveloper.com/t/select-duplicate-rename-export-layer-as-png-not-exporting-images/5902 "2023-02-22T09:04:11Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Charbel](https://avatars.discourse-cdn.com/v4/letter/c/9dc877/32.png) [@Charbel](https://forums.creativeclouddeveloper.com/u/Charbel)\
**Post date:** [February 22, 2023, 9:04am UTC](https://forums.creativeclouddeveloper.com/t/select-duplicate-rename-export-layer-as-png-not-exporting-images/5902/1 "2023-02-22T09:04:11Z")

</div>

the code was functional only one time, before I need to restart my machine, now it is bugged it is doing the whole job correctly but not exporting anything, though for some reason I had to wait before runing the

```auto
const export_and_renameLayer = async (layerID, newLayerName, path) => {
  const action = require("photoshop").action;
  const core = require("photoshop").core;

  console.log("[RENAME TO] :", newLayerName);
  console.log("[SAVE IN] :", path);

  const listOfDescriptors = [
    {
      _obj: "select",
      _target: [
        {
          _ref: "layer",
          _id: layerID,
        },
      ],
      makeVisible: false,
      layerID: [layerID],
      _isCommand: false,
    },
    {
      _obj: "copyToLayer",
      _options: {
        dialogOptions: "dontDisplay",
      },
    },
    {
      _obj: "set",
      _target: [
        {
          _ref: "layer",
          _enum: "ordinal",
          _value: "targetEnum",
        },
      ],
      to: {
        _obj: "layer",
        name: newLayerName,
      },
      _options: {
        dialogOptions: "dontDisplay",
      },
    },
    {
      _obj: "select",
      _target: [{ _ref: "layer", _name: newLayerName }],
      makeVisible: true,
      _isCommand: false,
      _options: { dialogOptions: "dontDisplay" },
    },
    {
      _obj: "exportSelectionAsFileTypePressed",
      _target: { _ref: "layer", _enum: "ordinal", _value: "targetEnum" },
      fileType: "png",
      quality: 32,
      metadata: 0,
      destFolder: path,
      sRGB: true,
      openWindow: false,
      _options: { dialogOptions: "dontDisplay" },
    },
    {
      _obj: "delete",
      _target: [
        {
          _ref: "layer",
          _enum: "ordinal",
          _value: "targetEnum",
        },
      ],
      layerID: [13],
      _options: {
        dialogOptions: "dontDisplay",
      },
    },
  ];

  await wait(50).then(async () => {
    await core.executeAsModal(
      async () => {
        await action.batchPlay(listOfDescriptors, {
          modalBehavior: "execute",
          synchronousExecution: false,
        });
      },
      { commandName: `Export ${newLayerName} Layer As PNG start` }
    );
  });
};

export_and_renameLayer(layerID, "exported_image_name", "/Users/machineName/Desktop/demo/");

```
