Help with adjusting InDesign script (imagesToCSV104.jsx)
Hi
I've been using this images to csv script (imagesToCSV104.jsx) for years. Unfortunatelly it does not work anymore as it should. It doesn't sort the image list in an alphanumeric order into csv file. I'm using OS Sonoma, and the image list is in irregular order.
Please, could somebody help me to update the code to add name sorting in it?
Array.prototype.inArray = function(obj){
var arrMax = this.length-1;
for(var i=arrMax; i>=0; i--){
if(this[i]===obj){
return true;
}
}
return false;
}
var csvParser = (function(){
var csvFile;
return{
create:function(fo){
csvFile=File(fo+"/"+fo.name+".csv");
},
write:function(csvContent){
csvFile.open('w');
csvFile.encoding="UTF-8";
csvFile.write(csvContent);
csvFile.close();
},
execute:function(){
csvFile.execute();
},
getCSV:function(){
return csvFile;
}
}
})();
function imagesToCSVthenChoose(){
var doc,
fo,
fis,
fiMax,
fi,
fiName,
fiPath,
imgFormats=["eps","jpg","tif","psd","pdf","png","ai","bmp","jpeg"],
imgFormatMax = imgFormats.length-1,
imgOk = [],
csvContent = [],
ext,
csvLine=[],
csvSep=",";
if(app.documents.length==0){
alert("No documents open !");
return
}
doc=app.activeDocument;
fo = Folder.selectDialog("Please choose a folder with images");
if(!fo) return
fis = fo.getFiles();
fiMax=fis.length;
for(var i=0; i<fiMax; i++){
fi=fis[i];
ext = fi.name.match(/\.([a-z]+)$/i);
if(ext==null) continue;
ext = ext[1].toLowerCase();
if(!imgFormats.inArray(ext)) continue;
fiName = decodeURI(fi.name);
fiPath=decodeURI(fi.fsName);
csvContent.push(fiName+csvSep+fiPath);
}
csvContent = "Name"+csvSep+"@images\r"+csvContent.join("\r");
csvParser.create(fo);
csvParser.write(csvContent);
/*
doc.dataMergeProperties.selectDataSource(csvParser.getCSV());
var myMenuAction = app.menuActions.item("$ID/DataMergePanelName");
myMenuAction.invoke();
*/
}
imagesToCSVthenChoose();
