ExtendScript for Updating Links on InDesing 2014
Hello everybody
I am using this a script to update the image links inside my INDD files, but I am unable to use it on my inDesign 2014. Does anybody know what changed on the latest version that the method update(); is no longer updating the links?
Here follows the code I have done to update the links
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
var numberOfEntriesFound = 0;
start();
function start() {
var targetFolder = Folder.selectDialog("Select a magazine folder to search for INDD files:");
var targetFolderPath;
if (targetFolder != null) {
targetFolderPath = targetFolder.fsName;
} else {
exit();
}
var topFolder = (new Folder(targetFolderPath));
forEachDescendantFile(topFolder, doStuffIfdocument);
if (numberOfEntriesFound == 0) {
alert('Process finsihed: No INDD were found under the given folder.');
} else {
alert('Process finsihed: ' + numberOfEntriesFound + ' INDD files were updated.');
}
}
function forEachDescendantFile(folder, callback) {
var aChildren = folder.getFiles();
for (var i = 0; i < aChildren.length; i++) {
var child = aChildren;
if (child instanceof File) {
callback(child);
} else if (child instanceof Folder) {
this.forEachDescendantFile(child, callback);
} else {
throw new Error("The object at \"" + child.fullName + "\" is a child of a folder and yet is not a file or folder.");
}
}
}
function doStuffIfdocument(oFile) {
if (matchExtension(oFile, "indd")) {
numberOfEntriesFound++;
var document = app.open(oFile);
try {
doStuff(document);
} finally {
document.close(SaveOptions.YES);
}
}
}
function doStuff(document) {
document.links.everyItem().update();
}
/*********** HELPERS FUNCTIONS ********************/
/**
* Returns true if the name of the given file ends in the given extension. Case insensitive.
*
* @9397041 {File} iFile
* @9397041 {String} sExtension The extension to match, not including the dot. Case insensitive.
* @Return {boolean}
*/
function matchExtension(iFile, sExtension) {
sExtension = "." + sExtension.toLowerCase();
var displayName = iFile.displayName.toLowerCase();
if (displayName.length < sExtension.length) {
return false;
}
return displayName.slice(-sExtension.length) === sExtension;
}