• Global community
    • Language:
      • Deutsch
      • English
      • EspaƱol
      • FranƧais
      • PortuguĆŖs
  • ę—„ęœ¬čŖžć‚³ćƒŸćƒ„ćƒ‹ćƒ†ć‚£
    Dedicated community for Japanese speakers
  • ķ•œźµ­ ģ»¤ė®¤ė‹ˆķ‹°
    Dedicated community for Korean speakers
Exit
0

UXPScript save file error with InDesign Server 2023

Community Beginner ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

I'm running UXPScript over SOAP request with InDesign Server 2023 running locally on my Windows machine. At the moment, UXPScript doesn't support arguments or returns, but it will run UXPScript if you send it in inside the <scriptText> tag like so (outer XML not shown):

<scriptText>
// actual script contents
</scriptText>

 

According to the documentation, we should have access to a "node-like" fs-module: https://developer.adobe.com/indesign/uxp/reference/uxp-api/reference-js/Modules/FileSystem/. It mentions that you can use "plugin-specific storage schemes" such as "plugin:", "plugin-data:", and "plugin-temp:", as well as a native "file:" scheme. Since I'm not developing a plugin, using a "file:" URI seems like the correct route. 

 

So the file I need to write within a folder that I created and have access to looks something like C:\Users\Me\Documents\temp_working_folder\data.json. So if I translate that to a file URI like the docs suggest, that gives me file:///C:/Users/Me/Documents/temp_working_folder/data.json.

 

When I try to use fs.writeFile, however, I get the following error:

 

TypeError: Cannot read properties of undefined (reading '_processWriteOptions')

 

Has anyone else gotten this error? Or has anyone successfully written data to a file on their file system using the "file:" URI scheme?

TOPICS
Bug , Experiment , How to , Scripting , UXP Scripting

Views

531

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 2 Correct answers

Community Beginner , May 19, 2023 May 19, 2023

Hi Darryl,

this snipped worked for me:

const fs = require("fs");
fs.writeFileSync(`file:C:/Users/JF/test.json`, JSON.stringify(data), {flag: "w",});

Hope this will help you.

 

Votes

Translate

Translate
Community Expert , May 19, 2023 May 19, 2023

At the moment, UXPScript doesn't support arguments or returns

 

As of ID 18.3, which became available this week, it does.

Votes

Translate

Translate
Community Beginner ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

Hi Darryl,

this snipped worked for me:

const fs = require("fs");
fs.writeFileSync(`file:C:/Users/JF/test.json`, JSON.stringify(data), {flag: "w",});

Hope this will help you.

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

@Jakob Frey Thank you!

 

To clarify some more for future readers, I found out additional information through some experimentation. It turns out their API documentation says that "mode" defaults to "w". But not including "w" gave me the error indicated in my original post. Once I explicitly included the mode as "w", it started to work (with a caveat). The caveat is that the promise fromthe asynchronous version (fs.writeFile) would never complete. But when I use the synchronous version (fs.writeFileSync) it completes successfully.

 

With that ability worked out, I found workarounds for including the arguments in the script and creating a result.json at a known location to get around the lack of support for arguments and returns with UXPScript. According to @Peter Kahrel, however, UXPScript now supports arguments and returns with ID 18.3 (which is great news). So hopefully I will update and that will make my workaround moot. But at least I know how to successfully write a file! šŸ¤£

 

Thank you to both of you guys for the support! šŸ™

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

At the moment, UXPScript doesn't support arguments or returns

 

As of ID 18.3, which became available this week, it does.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

@Peter Kahrel Thanks for the info! I will be trying to update so I can access this feature. I just finished prototyping a solution to get around the lack of arguments/returns, it will be nice to use the intended way now that it is ready.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 31, 2023 Jul 31, 2023

Copy link to clipboard

Copied

@Peter Kahrel I'm returning to this after a while and I've downloaded the latest InDesign Server (18.3), but seem to be unable to send script arguments as detailed in the documentation. I'm using the sample client that lives alongside the InDesign Server executable and trying to access the args with

require('uxp').script.args

but the args come up as an empty array no matter what I try.

Have you been able to confirm that args get sent when running 18.3, and if so, what process did you use to pass the args?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 31, 2023 Jul 31, 2023

Copy link to clipboard

Copied

Why not create a Label and pass arguments through it? As long as Server allows it...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 31, 2023 Jul 31, 2023

Copy link to clipboard

Copied

LATEST

I'm afraid I don't know. Sorry.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines