Okay, let's try this — please make sure to check the script very carefully after copying, because the forum software may attempt to prettify the code!
This script lets you select a single folder, then it goes over all .indd files in it, gathers your numbers, and finally lets you select an output file.
/* 1. What you want? */
var foundList = [];
var docFolder = Folder(Folder.myDocuments).selectDlg('Select a folder');
if (docFolder != null)
{
/* 2. How much of'em? */
fileList = docFolder.getFiles(“*.indd”);
for (f=0; f<fileList.length; f++)
{
/* 3. What you want with each? */
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.NEVER_INTERACT;
try {
doc = app.open (fileList[f]);
} catch (e)
{
foundList = foundList.concat ([fileList[f], “(Unable to open)”], '');
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
continue;
}
foundList = foundList.concat (getFoundList (doc));
doc.close(SaveOptions.NO);
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
}
}
/* 4. Where you want it? */
defaultFile = new File (Folder.myDocuments+”/numbers.csv”);
writeFile = defaultFile.saveDlg( 'Save report', File.fs == “Windows” ? “CSV file:*.csv;All files:*.*” : function(file) { return file instanceof Folder || (!(file.hidden) && file.name.match(/.csv$/i)); } );
if (writeFile != null)
{
if (writeFile.open(“w”))
{
writeFile.encoding = “utf8”;
writeFile.write (foundList.join('r')+'r');
writeFile.close();
} else
{
alert (“Something went wrong attempting to save!”);
}
}
function getFoundList (someDoc)
{
var i, thisDocList;
/* Where you at? */
var documentName = someDoc.name;
/* What you want? */
app.findGrepPreferences = null;
app.findGrepPreferences.findWhat = “\d{3}-\d{3}-\d{3}(?!\d)”;
thisDocList = someDoc.findGrep();
if (thisDocList.length == 0)
return [];
for (i=0; i<thisDocList.length; i++)
thisDocList[i] = thisDocList[i].contents;
/* Where you want it? */
return [ documentName ].concat(thisDocList);
}