# Migrating from Manifest 4 to 5 and UXP Photoshop.app.open not opening files

**URL:** <https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938>\
**Category:** UXP Plugin API\
**Tags:** react, uxp, javascript, api-feedback\
**Created:** [February 27, 2023, 11:29pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938 "2023-02-27T23:29:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 27, 2023, 11:29pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/1 "2023-02-27T23:29:33Z")

</div>

I need someone help clarify a things clear here. On manifest 4 I was using  
`photoshop.app.open(file)` and it was working correctly. I was getting the file from the server and opening it correctly. But on migrating to manifest 5 the file doesn’t open. yes the file gets downloaded successfully from my server to the disk but on trying to fetch it nothing happens. not even an error is thrown. What could be the reason since I’ve gone through the documentation and this change of things ain’t mentioned anywhere. Below is my code.

```auto
import photoshop from 'photoshop'
import uxp from 'uxp'

const fs = uxp.storage.localFileSystem

export const openMyFileAsDocument = (file: uxp.storage.File) => {
  console.log('opening file as document ', file)
  try {
    return photoshop.app.open(file as unknown as File)
  } catch (error) {
    console.log('error openng file as document', error)
  }
}

```

Besides, open the file as a layer also doesn’t seem to work on 5 as on 4. Am not sure where m getting it wrong since no exception is thrown

```auto
const openTheFileAsAlayer = (
  file: uxp.storage.File,
  replaceSelected?: boolean,
) => {
  console.log('opening file as layer ', file)
  if (photoshop.app.activeDocument) {
    return photoshop.action.batchPlay(
      [
       
        {
          _obj: replaceSelected ? 'placedLayerReplaceContents' : 'placeEvent',
          null: {
          
            _path: fs.createSessionToken(file),
            _kind: 'local',
          },
        },
      ],
      {
        synchronousExecution: false,
        modalBehavior: 'fail',
      },
    )
  } else {
    return // do something else
  }
}

```

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [February 28, 2023, 3:17am UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/2 "2023-02-28T03:17:35Z")

</div>

> file as unknown as File

what does this mean?

and how are you getting the entry to that file? I don’t see that in the code

* * *

for the 2nd issue you’ll need to use `executeAsModal` and remove `modalBehavior: 'fail'`

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 28, 2023, 7:25am UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/3 "2023-02-28T07:25:55Z")

</div>

> [@Adobe256](#):
>
> ```auto
> import photoshop from 'photoshop'
> import uxp from 'uxp'
> 
> const fs = uxp.storage.localFileSystem
> 
> export const openMyFileAsDocument = (file) => {
> console.log('opening file as document ', file)
> try {
> return photoshop.app.open(file)
> } catch (error) {
> console.log('error openng file as document', error)
> }
> }
> 
> ```

the As file was typescript version for it. the above is the same code but without typescript

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [February 28, 2023, 1:18pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/4 "2023-02-28T13:18:13Z")

</div>

1. have you added [Local Filesystem](https://developer.adobe.com/photoshop/uxp/2022/guides/uxp_guide/uxp-misc/manifest-v5/#local-filesystem) `requiredPermissions` to your manifest?

```auto
    "requiredPermissions": {
        "localFileSystem": "fullAccess"
    }

```

1. make sure the `file` is a valid entry.
2. wrap all related code in a try/catch and share whatever is logged in the debugger.

_if all fails:_  
I assume you’re using webpack since vanilla doesn’t support `import`  
could you run a minimal vanilla test to make sure everything is good and go from there?

```auto
async function openFile() {
    const fs = require("uxp").storage.localFileSystem;
    const app = require("photoshop").app;
    const f = await fs.getFileForOpening();
    await app.open(f);
}

```

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 28, 2023, 2:15pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/5 "2023-02-28T14:15:26Z")

</div>

I changed the code to using executeModal and the problem migrated to the following.` Error: Parameter must be a valid entry representing a file or a folder`  
below is the same code but with **execute as modal** and **try catch**

```auto
export const openFileAsDocument = async (file) => {
  console.log('opening file as document ', file)
  async function openDocument(file) {
    return await photoshop.app.open(file)
  }
  try {
    return await require('photoshop').core.executeAsModal(openDocument, {
      command: 'my script',
    })
  } catch (error) {
    console.log('error openng file as document', error)
  }
}

```

below is my uxp log

 ![saving issue](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/8/80d3ad3450848032cb6e37df71f86806b71fc4bb.png)

I’ve also granted fullAccess to localFileSystem

---

<div class="post-metadata">

**Author:** ![Karmalakas](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/karmalakas/32/1048_2.png) [@Karmalakas](https://forums.creativeclouddeveloper.com/u/Karmalakas)\
**Post date:** [February 28, 2023, 2:30pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/6 "2023-02-28T14:30:07Z")

</div>

I think your ` async function openDocument(file)` doesn’t actually recieve that argument `file` and inside the function it becomes `null`. Try changing to

```auto
executeAsModal(() => openDocument(file), ...)

```

And avoid using identical names in the same scope, like

```auto
func1(name) {
  func2(name) {
    // ...
  }

  func2()
}

```

Change to

```auto
func1(name1) {
  func2(name2) {
    // ...
  }

  func2(name1)
}

```

This way you would notice issues more quickly

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [February 28, 2023, 2:45pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/7 "2023-02-28T14:45:04Z")

</div>

the entry object logged seems to be valid.  
however the argument received by `openDocument` is not what you think.

functions called by `executeAsModal` recieve `executionContext` as first argument

please try the following:

```auto
const app = require("photoshop").app;
const core = require('photoshop').core;

export const openFileAsDocument = async (file) => {
    core.executeAsModal(async (executionContext) => {
        await app.open(file)
       // the rest of your code here
}, { "commandName": "Opening File" })
}

```

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 28, 2023, 2:48pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/8 "2023-02-28T14:48:48Z")

</div>

thanks alot. it has worked. posting it for someone else who might get stack. This is in typescript format.

```auto
export const openFileAsDocument = async (file) => {
  console.log('opening file as document ', file)
  async function openDocument() {    
    return await photoshop.app.open(file)
  }
  try {
    return await require('photoshop').core.executeAsModal(openDocument, {
      command: 'opening file',
    })
  } catch (error) {
    console.log('error opening file as document', error)
  }
}

```

the only issue is, I see this logged on the console.` Error: document Return value could not be coerced to action descriptor`

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [February 28, 2023, 3:01pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/9 "2023-02-28T15:01:10Z")

</div>

Where exactly do we make use of the execution context. I’ve seen it in the documentation and I’m unable to figure it out properly, with both the descriptor.  
According to my understanding of the documentation, the target function refers to the function passed as an argument to execute as modal. so in my case above the **OpenDocument** function is the target function.

Then the documentation says that the target function again takes in the **executionContext** and the **descripto** r?

Now I get more confused .  
here is the pic

 ![targetFunc](https://us1.discourse-cdn.com/flex015/uploads/xdplugins/original/2X/f/f2a04ee9c7f6356dee655d90f0726647b309fe5d.png)

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [February 28, 2023, 3:16pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/10 "2023-02-28T15:16:19Z")

</div>

`executionContext` can be used to `suspendHistory` as follows:

```auto
   let hostControl = executionContext.hostControl;
   let suspensionID = await hostControl.suspendHistory({
      "documentID": app.activeDocument.id,
      "name": "My Plugin Command"
   });

  // your code here

 await hostControl.resumeHistory(suspensionID);

```

this will create an entry in history called “My Plugin Command” that can be used for undo / redo.

we can also use `executionContext` to `reportProgress`  
it will update the progress bar acoording to set value (0 to 1)

`executionContext.reportProgress({"value": 0.5});`

---

<div class="post-metadata">

**Author:** ![Maher](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/maher/32/1432_2.png) [@Maher](https://forums.creativeclouddeveloper.com/u/Maher)\
**Post date:** [February 28, 2023, 4:04pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/11 "2023-02-28T16:04:27Z")

</div>

> [@Adobe256](#):
>
> the only issue is, I see this logged on the console.` Error: document Return value could not be coerced to action descriptor`

the method [open](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/photoshop/#open) returns a [document](https://developer.adobe.com/photoshop/uxp/2022/ps_reference/classes/document/) object

what are you trying to do with it?

---

<div class="post-metadata">

**Author:** ![Adobe256](https://avatars.discourse-cdn.com/v4/letter/a/3e96dc/32.png) [@Adobe256](https://forums.creativeclouddeveloper.com/u/Adobe256)\
**Post date:** [March 1, 2023, 1:44pm UTC](https://forums.creativeclouddeveloper.com/t/migrating-from-manifest-4-to-5-and-uxp-photoshop-app-open-not-opening-files/5938/12 "2023-03-01T13:44:27Z")

</div>

I only want to open that document and set xmp metadata. That’s it
