Page 1 of 1

JavaScript to Save as idml file in Indesign

Posted: Wed Jan 30, 2013 5:11 pm
by Flow666
I need to save some Indesign document to older versions (idml).

But i can't find any samples from javascript in combination with Switch on how to do this.



Can somebody point me to some sample files.

The manual from Switch isnt very helpfull.



JavaScript to Save as idml file in Indesign

Posted: Wed Jan 30, 2013 6:27 pm
by dkelly
You could try something like:





var regex = /.indd/gi

var fileName = app.activeDocument.fullName.replace(regex, ".idml");

app.activeDocument.save(File(fileName), true);


JavaScript to Save as idml file in Indesign

Posted: Wed Jan 30, 2013 9:32 pm
by Flow666
I am using the Indesign Configurator to process my jobs.



The settings i use are:

Open = Automatic

Command = None

Save = Use Script



var regex = /.indd/gi

var fileName = app.activeDocument.fullName.replace(regex, ".idml");

app.activeDocument.save(File(fileName), true);



Do i have to use the $code instead of app.activeDocument to get it working?



Or do i use the code in SwitchScripter?

I am getting errors that no documents are open.



JavaScript to Save as idml file in Indesign

Posted: Thu Jan 31, 2013 3:59 pm
by freddyp
Yes, you do and you have to fill out the $outfiles array so Switch knows what output files your script created. See the Switch help: Introduction - Advanced topics for designing flows -Javascript for applications.



Here is the code:



var tempDir = "/Users/fp/Desktop/";

var fileName = $doc.name.replace(".indd",".idml");



$doc.exportFile("InDesign Markup (IDML)",tempDir+fileName);

$outfiles = []

$outfiles.push(tempDir+fileName);

$doc.close;



Switch will automatically remove the temporary file, by the way.



Freddy

JavaScript to Save as idml file in Indesign

Posted: Thu Jan 31, 2013 4:45 pm
by Flow666
Thanks dkelly and freddyp. It works!!



I found that in my older script the documents where still open, but not visable.

With the $doc and $outfiles it works, thanks a lot.