• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

export every open file to idml

Explorer ,
Jun 11, 2020 Jun 11, 2020

Copy link to clipboard

Copied

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.

TOPICS
Scripting

Views

549

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Advisor , Jun 11, 2020 Jun 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

Votes

Translate

Translate
Advisor ,
Jun 11, 2020 Jun 11, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 11, 2020 Jun 11, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 11, 2020 Jun 11, 2020

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 11, 2020 Jun 11, 2020

Copy link to clipboard

Copied

Hi Rob,

 

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

 

Tak

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 12, 2020 Jun 12, 2020

Copy link to clipboard

Copied

LATEST

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 )

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines