Skip to main content
Bruno Ferdigg
Participant
October 16, 2023
Question

scripts

  • October 16, 2023
  • 4 replies
  • 1303 views

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

This topic has been closed for replies.

4 replies

brian_p_dts
Community Expert
Community Expert
October 16, 2023

Can you post the script you're working with? Probably just a matter of using app.open(file) somewhere. 

Bruno Ferdigg
Participant
October 17, 2023

Hey, this is the script. thnx

  1. //InxAfterSafe.jsx
    #targetengine "session"
    main();

    function main()
    {
    var myEventListener1 = app.addEventListener("afterSave", IDML_Export, false);
    var myEventListener2 = app.addEventListener("afterSaveAs", IDML_Export, false);
    }

    function IDML_Export()
    {
    var myFileName = app.activeDocument.fullName.fullName.replace(/\.indd$/i, "") + ".idml";
    app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, File(myFileName));
    }
Bruno Ferdigg
Participant
October 23, 2023

@brian_p_dts can you help me?? thanks

Anantha Prabu G
Legend
October 16, 2023

Hi @Bruno Ferdigg 

 

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")



Design smarter, faster, and bolder with InDesign scripting.
Robert at ID-Tasker
Legend
October 16, 2023

@Anantha Prabu G 

You missed the point - OP wants to export IDML every time INDD file is open - not a folder full of INDD files. 

 

Anantha Prabu G
Legend
October 17, 2023

YES. I got it.

Every time we open the INDD files it should be saved as an IDML file as backup.

Design smarter, faster, and bolder with InDesign scripting.
Robert at ID-Tasker
Legend
October 16, 2023

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? 

 

jane-e
Community Expert
Community Expert
October 16, 2023

@Bruno Ferdigg 

 

I've moved your post from Creative Cloud Desktop to the InDesign forum and added the topic for Scripting for you.

 

Jane