Question
how to save selected image in inDesign using uxp code
Can anyone help how to save selected image save in local drive in inDesign uxp code structure. below given code is not working for me.
const app = global.app ?? require("indesign").app;
async function saveImage() {
const selection = app.activeDocument.selection;
if (selection) {
const selectedImage = selection[0];
if (selectedImage) {
try {
const imageCopy = selectedImage.duplicate();
imageCopy.exportFile("JPG", "");
console.log("Image saved successfully!");
imageCopy.remove();
} catch (error) {
console.log("Error saving image: " + error);
}
} else {
console.log("The selected item is not an image.");
}
} else {
console.log("No item selected. Please select an image to save.");
}
}
