The problem is simple - I created an InDesign script (V8 engine - .idjs) which writes to a file (see code below). When I run the code code from a .idjs script, it works well. When I run it from an InDesign plugin, I get the error: ‘Route not found’.#@$%µ§
The old ESTK has the File class which works well. The problem is that it cannot be used in a plugin as the plugin uses the V8 engine which does not support the File class.
I encounter the same problem when using the writeFileSync method.
I’ve dedicated a lot of time trying to write to a file from an InDesign plugin. Would anyone have a solution?
CODE:
await WriteToFile(“some text”, ‘a’);
async function WriteToFile(text, mode) {
try {
await fs.writeFile(“D:/Perso/Books/InDesign/newFile.txt”,text, {flag:mode, encoding: “utf8”});
} catch(e) {
DisplayMsg("WriteToFile ERROR: " + e); // Dialog box to display a message
}
} // WriteToFile
As I search this forum for pointers on the problem I was having, I discovered what seems to be an interesting conclusion. It seems that Adobe provides two file systems - one which works with V8 engine scripts:
const fs = require(“fs”);
and one which works with plugins:
const fs = require(“uxp”).storage.localFileSystem;
Here is the code to write to a file from a plugin:
async function WriteToFile(fileName, text, mode, dir) {
try {
const pluginDataFolder = await fs.getDataFolder();
const file = await pluginDataFolder.createFile(“output.txt”, { overwrite: true });
await file.write(text, { append: false });
var nativePath = file.nativePath;
} catch(e) {
DisplayMsg("WriteToFile ERROR: " + e);const fs = require(“fs”);
return;
}
DisplayMsg("WriteToFile SUCCESS ?? - see file.nativePath: " + nativePath);
} // WriteToFile
The only problem is that the file gets put deep down in the system c:/Users… folder which can be a real pain to acces. The solutoin is to create a linked directory (mklink) in a convenient place.
Please consider this issue solved.
Have you written your manifest permissions along those implied for UXPScript?
Edit: The linked page differs from the preview, refer to the section “Permission module for Scripts”.