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.
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
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
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
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.
Copy link to clipboard
Copied
Hi Rob,
Yes, the open docs have been saved. Thanks for the reminder, though.
Tak
Copy link to clipboard
Copied
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 )