Help with "Smart Object Replace Contents"

I am trying to replace the content of a smart object layer with the following function.
I can’t get the proper token for the “placedLayerReplaceContents”
Do I need a special function to Get File For Placing or ???
Can someone help?

const batchPlay = require(“photoshop”).action.batchPlay
const app = require(“photoshop”).app
const UXP = require(“uxp”)

const fs = require(“uxp”).storage.localFileSystem
var exeModal = require(“photoshop”).core.executeAsModal
var theFile
var myFile

const test3 = async () => {

await exeModal(async () => {

theFile = await fs.getFileForOpening();
myFile = theFile.nativePath
console.log(myFile)

const result = await batchPlay(
[
{
_obj: “placedLayerReplaceContents”,
null: {
_kind: “local”,
_path: myFile
},
_options: {
dialogOptions: “display”
}
}
],{
synchronousExecution: false,
modalBehavior: “execute”
})
})
}

1 Like

Try this code, before, select layer:
file is result of folder.getEntry().

await action.batchPlay(
            [
              {
                _obj: "placedLayerReplaceContents",
                null: {
                  _path: uxp.storage.localFileSystem.createSessionToken(file),
                  _kind: 'local',
                },
              },
            ],
            {}
        );