8

Is there an existing script for InDesign that will save an INDD file and an IDML copy at the same time?

I work with dozens of independent designers on collaborative projects, and those of us with Creative Cloud have to remember to save an IDML copy for those on earlier versions. And we often forget.

I'm hoping to find or tweak a script that will, for instance, add a menu item called, say, 'Save with IDML', and will save both the current document and an IDML copy alongside it.

  • You could always package, instead of save – Manly May 26 '16 at 18:20
7

This example should get you started. You need to run the script once per InDesign session. You could add it as a startup script for example. It will save everytime the user saves the document a idml file.

#targetengine "session"
// we need a targetegine to make this work
var doc = app.activeDocument; // get the current doc

// now to the event listener
app.addEventListener('afterSave', function(theEvent) {
  $.writeln('saving'); // just to see whats going on
  if (!doc.saved) {
    // catch those possible mistakes
    alert('doc was never saved');
    exit();
  }
  var aName = doc.name; // get the name
  var newName = aName.replace("indd", "idml"); // replace the indd to idml
  // crate a new File Object next to the indd
  var theFile = File(File(doc.filePath).fsName + "/" + newName);
  // export
  doc.exportFile(ExportFormat.INDESIGN_MARKUP, theFile, false);
});

If you want this as a menu command you could take look into this blog post on indiscripts.

|improve this answer|||||
5

Thanks, @fabiantheblind, that works brilliantly. I've adapted that to make it work as a Startup Script (it waits for a document to be opened).

// Set a targetengine to make this work
#targetengine "session"

function saveIDML() {
    // Exit if no documents are open.
    if(app.layoutWindows.length == 0) {
        return;
    } else {
        // Get the current document
        var doc = app.activeDocument;
        $.writeln('Saving IDML of ' + doc + ' ...');
        // Catch errors
        if (!doc.saved) {
          alert('Sorry, there was a problem and the document was not saved.');
          exit();
        }
        // Create a new .idml file name from the .indd file name
        var inddName = doc.name;
        var idmlName = inddName.replace("indd", "idml");
        // Create the new .idml file next to the .indd file
        var theFile = File(File(doc.filePath).fsName + "/" + idmlName);
        doc.exportFile(ExportFormat.INDESIGN_MARKUP, theFile, false);
    }
}
// Listen for the save event
app.addEventListener('afterSave', saveIDML, false);
|improve this answer|||||
  • 1
    This doesn't make sense - you're re-adding the event listener with every opened document. That means e.g. after the fifth opened document, the export will happen five times! Just use fabian's script and you're fine – Tobias Kienzler Jul 11 '17 at 11:02
  • Thanks, @TobiasKienzler! I've edited my version to avoid that. – Arthur Apr 2 '18 at 8:33
  • Looks much better to me :) – Tobias Kienzler Apr 2 '18 at 18:26
0

I have found @Arthur's script very useful. However, I wanted to use it only only afterSave, but also afterSaveAs (which was easy to extend: just append another event listener command) and afterSaveACopy (which I could not accomplish by myself; I have seeked the help at community.adobe.com).

Now I have a working script that works for all three use cases, see below.

// src: https://community.adobe.com/t5/indesign/get-the-name-of-the-document-created-by-save-a-copy/m-p/10997427#M179868 (based on https://graphicdesign.stackexchange.com/a/71770, which is based on https://graphicdesign.stackexchange.com/a/71736)
// author: Fabian Morón Zirfas (fabianmoronzirfas@graphicdesign.stackexchange.com), modified by Arthur (Arthur@graphicdesign.stackexchange.com), modified by Sunil_Yadav1 (Sunil_Yadav1@community.adobe.com)
// date: 24 March 2020

// Set a targetengine to make this work
#targetengine "session"

function saveIdml() {
    if(app.layoutWindows.length == 0) {
        return;
    } else if (! app.activeDocument.saved) {
        alert('Sorry, there was a problem and the document was not saved.');
        return;
        }

    var idmlPath = app.activeDocument.filePath.fsName.replace(/\\/g,'/') + '/' + app.activeDocument.name.replace(/\.indd|\.indt/g, '.idml');
    app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, idmlPath, false);
    }

function saveACopyIdml(e) {
    var idmlPath = File(e.properties.fullName).fsName.toString().replace(/\\/g,'/').replace(/\.indd|\.indt/g, '.idml');
    app.activeDocument.exportFile(ExportFormat.INDESIGN_MARKUP, idmlPath, false);
    }

// Listen for the save event
app.addEventListener('afterSave', saveIdml, false);
app.addEventListener('afterSaveAs', saveIdml, false);
app.addEventListener('afterSaveACopy', saveACopyIdml, false);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.