Inserting local image from plugin folder to active document

I don’t know if something is missing or what I’m doing wrong, because I can’t insert any local image from the plugin folder to the active document using the code below. Thanks in advance!

async function openTemplate() {
    const app = window.require("photoshop").app;
    const fs = require("uxp").storage.localFileSystem;
    const pluginFolder = await fs.getPluginFolder();
    const theTemplate = await pluginFolder.getEntry("icons/AjustColor.psd");
    await app.batchPlay([{"ID":64,"_obj":"placeEvent","freeTransformCenterState":{"_enum":"quadCenterState","_value":"QCSAverage"},"null":{"_kind":"local","_path":theTemplate.nativePath},"offset":{"_obj":"offset","horizontal":{"_unit":"pixelsUnit","_value":0.0},"vertical":{"_unit":"pixelsUnit","_value":0.0}},"replaceLayer":{"_obj":"placeEvent","to":{"_id":64,"_ref":"layer"}}}], {});
}

Try removing window. from your first import as it shouldn’t be there.

async function openTemplate() {
    const app = require("photoshop").app;
    const fs = require("uxp").storage.localFileSystem;
    const pluginFolder = await fs.getPluginFolder();
    const theTemplate = await pluginFolder.getEntry("icons/AjustColor.psd");
    try {
      await app.batchPlay([{"ID":64,"_obj":"placeEvent","freeTransformCenterState":{"_enum":"quadCenterState","_value":"QCSAverage"},"null":{"_kind":"local","_path":theTemplate.nativePath},"offset":{"_obj":"offset","horizontal":{"_unit":"pixelsUnit","_value":0.0},"vertical":{"_unit":"pixelsUnit","_value":0.0}},"replaceLayer":{"_obj":"placeEvent","to":{"_id":64,"_ref":"layer"}}}], {});
    } catch (err) {
      console.log(err);
    }
  }

In console.Log I get this even with the change.

It only worked when adding this:

  const theTemplate = await pluginFolder.getEntry("icons/AjustColor.psd");
  const token = await fs.createSessionToken(theTemplate)
///////////////////////
await app.batchPlay([{xxxx, _path":token}], {})
1 Like