# Help with "Smart Object Replace Contents"

**URL:** <https://forums.creativeclouddeveloper.com/t/help-with-smart-object-replace-contents/4796>\
**Category:** Photoshop\
**Tags:** ui, uxp, javascript\
**Created:** [June 14, 2022, 4:34pm UTC](https://forums.creativeclouddeveloper.com/t/help-with-smart-object-replace-contents/4796 "2022-06-14T16:34:06Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pdophoto](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/pdophoto/32/1304_2.png) [@pdophoto](https://forums.creativeclouddeveloper.com/u/pdophoto)\
**Post date:** [June 14, 2022, 4:34pm UTC](https://forums.creativeclouddeveloper.com/t/help-with-smart-object-replace-contents/4796/1 "2022-06-14T16:34:06Z")

</div>

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”  
> })  
> })  
> }

---

<div class="post-metadata">

**Author:** ![Bianca](https://avatars.discourse-cdn.com/v4/letter/b/3be4f8/32.png) [@Bianca](https://forums.creativeclouddeveloper.com/u/Bianca)\
**Post date:** [January 29, 2025, 1:47pm UTC](https://forums.creativeclouddeveloper.com/t/help-with-smart-object-replace-contents/4796/2 "2025-01-29T13:47:40Z")

</div>

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

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

```
