batch update links indesign

some years ago, I found a really helpfull script for updating links in indesign documenten.
The script is in “jsx”. I only know a littlebit about applescript.

Recently we have updated our indesign version to CC. Now the script doesn’t run because the version is older than “5”.

Can anyone adapt the script for Indesign CC?

var myInDesignVersion = Number(String(app.version).split(".")[0]);

var myFolder = Folder.selectDialog("Select a folder with InDesign files to resave");
if (myFolder == null) exit();
var myFilelist = [];
var myAllFilesList = myFolder.getFiles();

for (var f = 0; f < myAllFilesList.length; f++) {
	var myFile = myAllFilesList[f];
	if (myFile instanceof File && myFile.name.match(/\.indd$/i)) {
		myFilelist.push(myFile);
	}
}
if (myInDesignVersion < 5) {
	alert("This script is for InDesign CS3/4.", "Batch update links script");
	exit();
}

if (myFilelist.length == 0) {
	alert("No files to open.", "Batch update links script");
	exit();
}

var myCounter = 1;
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;

// Progress bar -----------------------------------------------------------------------------------
var myProgressWin = new Window ( "window", "Batch update links script" );
var myProgressBar = myProgressWin.add ("progressbar", [12, 12, 350, 24], 0, myFilelist.length);
var myProgressTxt = myProgressWin.add("statictext", undefined, "Starting updating files");
myProgressTxt.bounds = [0, 0, 340, 20];
myProgressTxt.alignment = "left";
myProgressWin.show();
// Progress bar -----------------------------------------------------------------------------------

for (var i = myFilelist.length-1; i >= 0; i--) {
	var myCurrentFile = myFilelist[i];
	
	try {
		var myDoc = app.open(myCurrentFile, false);
		var myDocName = myDoc.name;

		// Progress bar -----------------------------------------------------------------------------------
		myProgressBar.value = myCounter;
		myProgressTxt.text = String("Updating file - " + myDocName + " (" + myCounter + " of " + myFilelist.length + ")");
		
		// Progress bar -----------------------------------------------------------------------------------
		UpdateAllOutdatedLinks();
		myDoc = myDoc.save();
		myDoc.close(SaveOptions.NO);

		myCounter++;
	}
	catch(e) {}
}

	// Progress bar -----------------------------------------------------------------------------------
	myProgressWin.close();
	// Progress bar -----------------------------------------------------------------------------------

app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;

alert("Done.", "Batch update links script");

//--------------------------------------------------------------------------------------------------------------
function VerifyFolder(myFolder) {
	if (!myFolder.exists) {
		var myFolder = new Folder(myFolder.absoluteURI);
		var myArray1 = new Array();
		while (!myFolder.exists) {
			myArray1.push(myFolder);
			myFolder = new Folder(myFolder.path);
		}
		myArray2 = new Array();
		while (myArray1.length > 0) {
			myFolder = myArray1.pop();
			if (myFolder.create()) {
				myArray2.push(myFolder);
			} else {
				while (myArray2.length > 0) {
					myArray2.pop.remove();
				}
				throw "Folder creation failed";
			} 
		}
	}
}
//--------------------------------------------------------------------------------------------------------------
function UpdateAllOutdatedLinks() {
	for (var myCounter = myDoc.links.length-1; myCounter >= 0; myCounter--) {
		var myLink = myDoc.links[myCounter];
		if (myLink.status == LinkStatus.linkOutOfDate) {
			myLink.update();
		}
	}
}
//--------------------------------------------------------------------------------------------------------------

I tried to write an applescript… I got an error on "“set theLinks to every link”. What am I doing wrong?


tell application "Adobe InDesign CC"
	tell active book
		set fileList to full name of book contents
	end tell
	
	--create new layer	
	repeat with aFile in fileList
		set theDoc to open aFile without showing window
		set theLinks to every link
		repeat with aLink in theLinks
			
			if status of aLink is link out of date then
				update aLink
			else
				if status of aLink is link missing then -- other options are normal/link out of date/link missing/link embedded
					--missing link handling
					display dialog "Missing"
				end if
			end if
		end repeat
		close every document saving yes
	end repeat
end tell --End tell InDesign

You’re not addressing the document. Try “set theLinks to every link of theDoc”.