Question
uxp app undefined
In below code always got app undefined in below code inside function readInDesignContent()
const { entrypoints , host} = require("uxp");
const { app } = require("indesign");
entrypoints.setup({
commands: {
showAlert: () => readInDesignContent()
},
panels: {
showPanel: {
show({node} = {}) {}
}
}
});
async function readInDesignContent() {try {
// Access the UXP context
const { app } = require('uxp').shell;
// Check if the app object is defined
if (!app) {
console.log("Error: 'app' object is undefined.");
return;
}
// Check if there is an active document
if (app.activeDocument) {
const activeDocument = app.activeDocument;
// Access the textFrames in the active document
const textFrames = activeDocument.textFrames;
// Iterate through textFrames and log their contents
for (const textFrame of textFrames) {
console.log("Text Frame Content:", textFrame.text);
}
} else {
console.log("No active document found.");
}
} catch (error) {
console.error("Error:", error);
}
}
