change filename into link
i want change filename of link indesign. example: existing filename table_ex.jpg , want change table_cz.jpg
i wrote script, seems change 1 link. can me?
#target indesign
// relink file filename.js
if (app.documents.length == 0) {
err("no open document. please open document , try again.", true);
}
var mydoc = app.activedocument;
var mylinks = mydoc.links;
var mycounter = 0;
if (mylinks.length == 0) {
err("this document doesn't contain links.", true);
}
for (i = mylinks.length-1; >= 0 ; i--) {
var mylink = mylinks[i];
var myoldfilename = mylink.name;
var mynewfilename = myoldfilename.replace("_ex", "_cz");
var mynewfile = new file(mynewfilename);
if (mynewfile.exists) {
mylink.relink(mynewfile);
mycounter++;
}
}
document.save()
document.close()
probably relinking messes mylinks collection saved earlier.
a quick fix might to place line inside for..loop:
mylinks = mydoc.links;
.. it's kind of dirty trick. suppose loop keep working. if not, you'll have use infinite loop , keep on checking start, until made no change.
More discussions in InDesign Scripting
adobe
Comments
Post a Comment