Skip to main content
Inspiring
June 11, 2020
Answered

export every open file to idml

  • June 11, 2020
  • 3 replies
  • 798 views

I'm trying to export every open InDesign file to idml in the same folder.

(I'm trying javascript and Visual Studio Code for the first time.)

 

main();
function main(){

    var i;
    for (i = 0; i < app.documents.length - 1; i++) {
        fileName = app.documents.item(i).filePath + "/" + app.documents.item(i).name.split('.').slice(0, -1).join('.') + "\.idml";
        app.documents.item(i).exportFile(ExportFormat.INDESIGN_MARKUP, fileName);
    } 

}

 

But, I get the following error.

Runtime Error: Error Code# 48: Folder ""/c/temp/test.idml"" not found.

 

What do I need to do here?

I also need this to work if the path is to a folder on the Desktop (e.g., ""~/Desktop/temp/test.idml"").

 

Thanks.

This topic has been closed for replies.
Correct answer Mike Bro

Hello Tak Osato

The code below with some slight modifactions works for me.

 

main();
function main(){
  
var i;
for (i = 0; i < app.documents.length; i++) {
var fileName = app.documents.item(i).name.replace(/.indd/, ""); 
var myIDML = new File(File(app.documents.item(i).filePath).fsName + "/" + fileName + ".idml");
app.documents.item(i).exportFile(ExportFormat.INDESIGN_MARKUP, myIDML);
   } 

}

 

 

Regards,

Mike

3 replies

Community Expert
June 12, 2020

Hi Mike,

I would refine the RegExp used from:

replace(/.indd/, "");

to:

replace(/\.indd$/i,"");

 

Hope, the reason is obvious to you.

 

Regards,
Uwe Laubender

( ACP )

rob day
Community Expert
Community Expert
June 11, 2020

Have the open docs been saved? A file needs to have been saved for doc.filepath to return a folder.

Tak OsatoAuthor
Inspiring
June 11, 2020

Hi Rob,

 

Yes, the open docs have been saved. Thanks for the reminder, though.

 

Tak

Mike BroCorrect answer
Legend
June 11, 2020

Hello Tak Osato

The code below with some slight modifactions works for me.

 

main();
function main(){
  
var i;
for (i = 0; i < app.documents.length; i++) {
var fileName = app.documents.item(i).name.replace(/.indd/, ""); 
var myIDML = new File(File(app.documents.item(i).filePath).fsName + "/" + fileName + ".idml");
app.documents.item(i).exportFile(ExportFormat.INDESIGN_MARKUP, myIDML);
   } 

}

 

 

Regards,

Mike

Tak OsatoAuthor
Inspiring
June 11, 2020

Hi Mike,

 

Thanks! It worked.

 

If you don't mind me asking, what's the deal with

 

File(File(app.documents.item(i).filePath).fsName

 

When I put this in my "Watch" list, the value seems to be the same as my original fileName variable.

 

Tak