Skip to main content
Participant
January 29, 2024
Answered

UXP plugin Promises are forever pending

  • January 29, 2024
  • 1 reply
  • 640 views

I'm writing a plugin for indesign.
I want to read the name from the active document.
This is my code in a helper file:
```

const { ExportFormat, app } = require("indesign");
const {File} = require('fs');
class exportUtils {

async exportToEpub() {
try {
let doc = app.activeDocument;
let fullName = await doc.fullName;
 
console.log(fullName); // Directly log the fullName
 
let epubFileName = fullName.toString().replace(/\.[^\.]+$/, ".epub");
doc.exportFile(ExportFormat.FIXED_LAYOUT_EPUB, new File(epubFileName), false);
} catch (error) {
console.error(error);
}
};
}
```
The problem is fullName is a Promise and it never resolves.
I expected it to be a File object according to the api reference here: https://developer.adobe.com/indesign/dom/api/d/Document/
This topic has been closed for replies.
Correct answer Dirk Becker

UXP tries to mimic the full browser experience including all security circus.
See your promise details, maybe something about PromiseState "rejected" and PromiseResult Error: Could not find an entry … ?
This could be about missing permission requests in your manifest.
If your await works in an UXP Script, the difference is described here: https://developer.adobe.com/indesign/uxp/resources/fundamentals/manifest/
More details for plugins:
https://developer.adobe.com/indesign/uxp/plugins/concepts/manifest/
Basically you need:
"requiredPermissions": {
"localFileSystem": "fullAccess"
}
General info on Files the UXP way:
https://developer.adobe.com/indesign/uxp/reference/uxp-api/reference-js/Modules/uxp/Persistent%20File%20Storage/File/

 

1 reply

Dirk BeckerCorrect answer
Legend
January 29, 2024

UXP tries to mimic the full browser experience including all security circus.
See your promise details, maybe something about PromiseState "rejected" and PromiseResult Error: Could not find an entry … ?
This could be about missing permission requests in your manifest.
If your await works in an UXP Script, the difference is described here: https://developer.adobe.com/indesign/uxp/resources/fundamentals/manifest/
More details for plugins:
https://developer.adobe.com/indesign/uxp/plugins/concepts/manifest/
Basically you need:
"requiredPermissions": {
"localFileSystem": "fullAccess"
}
General info on Files the UXP way:
https://developer.adobe.com/indesign/uxp/reference/uxp-api/reference-js/Modules/uxp/Persistent%20File%20Storage/File/

 

Participant
January 31, 2024

Thank you, this helped me!