Copy link to clipboard
Copied
Hi, i have a script in InDesign, this script automatically creates an idml file from the document, how can I automate it so that it opens automatically with every document without starting it manually. Thanks a lot
Copy link to clipboard
Copied
I've moved your post from Creative Cloud Desktop to the InDesign forum and added the topic for Scripting for you.
Jane
Copy link to clipboard
Copied
It should be set up as an "onOpen" event - but I'm not JS guy so you need to wait for someone else for exact JS code.
But why do you need to do this every time you open INDD file?
A bit strange... Would make more sense on closing / saving INDD file - kind of extra backup?
Copy link to clipboard
Copied
Please choose the folder with INDD files.
var myFileLocation = Folder.selectDialog("Please select path to files"); // file path selection
myFolder = new Folder ([myFileLocation]);
myFolderContents = myFolder.getFiles("*.indd"); // array
myFileAmount = (myFolderContents.length - 1);
// ===== Open, Export as PDF, and Close files ===== \\
for (i = myFileAmount; i >= 0; i--)
{
app.open(File (myFolderContents[i]));
app.activeDocument.exportFile(
ExportFormat.INDESIGN_MARKUP,
new File(myFolder.fsName + "/" + app.activeDocument.name.split(".indd")[0] + ".idml"),
false);
app.activeDocument.close(SaveOptions.no);
}
alert("IDML Created")
Copy link to clipboard
Copied
You missed the point - OP wants to export IDML every time INDD file is open - not a folder full of INDD files.
Copy link to clipboard
Copied
YES. I got it.
Every time we open the INDD files it should be saved as an IDML file as backup.
Copy link to clipboard
Copied
Can you post the script you're working with? Probably just a matter of using app.open(file) somewhere.
Copy link to clipboard
Copied
Hey, this is the script. thnx
Copy link to clipboard
Copied
@brian_p_dts can you help me?? thanks
Copy link to clipboard
Copied
Hope this helps to you.
#target indesign
var myEventListener = app.addEventListener("afterSave", myAfterSaveFunction);
function myAfterSaveFunction(myEvent) {
var savedDoc = myEvent.parent;
// Check if the saved document is an InDesign document
if (savedDoc instanceof Document) {
// Define the IDML file path
var idmlFilePath = savedDoc.filePath + "/" + savedDoc.name.replace(/\.[^\.]+$/, "") + ".idml";
// Export the document to IDML format
savedDoc.exportFile(ExportFormat.INDESIGN_MARKUP, File(idmlFilePath));
alert("IDML file created successfully: " + idmlFilePath);
}
}
Thanks,
Prabu G
Copy link to clipboard
Copied
I think alert() at the end of the event is rather unnecessary?
And OP needs it onOpen.
Copy link to clipboard
Copied
Something like this? If I understand, you want to open the IDML after export. Of course, since this is a startup script, if you then save the exported idml again, it will trigger a new version.
#targetengine "session"
main();
function main()
{
var myEventListener1 = app.addEventListener("afterSave", IDML_Export, false);
var myEventListener2 = app.addEventListener("afterSaveAs", IDML_Export, false);
}
function IDML_Export()
{
try {
var myFileName = app.activeDocument.fullName.fullName.replace(/\.indd$/i, "") + ".idml";
app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, File(myFileName));
app.open(File(myFileName));
} catch(e) {}
}
Copy link to clipboard
Copied
I actually just want to automatically save the .idml file for every InDesign document and the script should start when the program InDesign starts. I want to do this because my work colleagues don't have the latest version of InDesign and I do. Without the .idml file they can't open my files, I usually forget to save the .idml file and would like to automate this. Thanks