polyfillForEach();
var inPath = "";
var defaultPath = new Folder;
var f = defaultPath.selectDlg("Выберите папку, в которой нужно скопировать линки к файлам indd.");
if (f && f.exists){
inPath = f.fullName;
}
if (inPath != "")
main();
function main() {
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
var files = find_files (inPath, ['.indd']);
if (!files.length) {
alert("В указанной папке нет файлов indd");
return;
}
var w = new Window ("palette", "Прогресс операций");
var pbar = w.add ("progressbar", undefined, 1, files.length);
pbar.preferredSize = [500,20];
w.show();
files.forEach( function (obj) {
var doc = app.open(obj, false);
processDocument(doc); pbar.value ++;
doc.close();
} );
w.close();
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
alert("Готово.");
}
function processDocument(doc)
{
mLinks = doc.links.everyItem().getElements();
mPath = doc.filePath + "/Links/";
if (!Folder(mPath).create()) exit();
for(i = mLinks.length - 1; i >=0 ; i--) {
currLinkFName = mLinks[i].filePath;
currFile = File( mPath + File(currLinkFName).name );
if (File(currLinkFName).exists & !File(currFile).exists)
mLinks[i].copyLink(currFile);
}
}
function find_files (dir, mask_array){
var arr = [];
for (var i = 0; i < mask_array.length; i++){
arr = arr.concat (find_files_sub (dir, [], mask_array[i].toUpperCase()));
}
return arr;
}
function find_files_sub (dir, array, mask){
var f = Folder (dir).getFiles ( '*.*' );
for (var i = 0; i < f.length; i++){
if (f[i] instanceof Folder){
find_files_sub (f[i], array, mask);
} else if (f[i].name.substr (-mask.length).toUpperCase() == mask){
array.push (f[i]);
}
}
return array;
}
function polyfillForEach () {
if(!Array.prototype.forEach){Array.prototype.forEach=function(callback,thisArg){var T,k;if(this==null){throw new TypeError(' this is null or not defined');}
var O=Object(this);var len=O.length>>>0;if(typeof callback!=='function'){throw new TypeError(callback+' is not a function');}
if(arguments.length>1){T=thisArg;}
k=0;while(k<len){var kValue;if(k in O){kValue=O[k];callback.call(T,kValue,k,O);}
k++;}};}
}