Peter Kahrel's script
// Description: Place multiple textfiles as one story
#target indesign
preset = '/d/test/*.rtf';
app.wordRTFImportPreferences.useTypographersQuotes = true;
app.wordRTFImportPreferences.convertPageBreaks = ConvertPageBreaks.none;
app.wordRTFImportPreferences.importEndnotes = true;
app.wordRTFImportPreferences.importFootnotes = true;
app.wordRTFImportPreferences.importIndex = true;
app.wordRTFImportPreferences.importTOC = false;
app.wordRTFImportPreferences.importUnusedStyles = false;
mask = prompt ('Enter a file path/mask.rr' +
'Examples:r' +
'd:bookstest*.rtf /d/books/test/*.rtf', preset);
if (mask == null) exit(); // Cancel pressed
ff = Folder (File (mask).path).getFiles (File (mask).name);
if (ff.length > 0)
{
placed = [];
missed = [];
tframe = app.documents.add().textFrames.add({geometricBounds : [36, 36, 400, 400]});
placedstory = tframe.parentStory;
app.scriptPreferences.userInteractionLevel =
UserInteractionLevels.neverInteract;
pb = initprogressbar (ff.length, 'Loading');
for (i = 0; i < ff.length; i++)
{
pb.value = i;
try
{
placedstory.insertionPoints[-1].place (ff[i]);
placedstory.insertionPoints[-1].contents = 'rr';
placed.push (ff[i].name);
}
catch (_)
{
missed.push( ff[i].name );
}
}
app.scriptPreferences.userInteractionLevel =
UserInteractionLevels.interactWithAll;
inform = '';
if (placed.length > 0)
inform = 'Placed ' + ff.length + ' files (in this order):rr' + placed.join ('r');
if (missed.length > 0)
inform += 'rrCould not place:rr' + missed.join ('r');
delete_empty_frames ();
alert( inform );
}
else
alert (mask + ' not found.');
// End
function delete_empty_frames ()
{
app.findGrepPreferences = app.changeGrepPreferences = null;
app.findGrepPreferences.findWhat = 'AZ';
var empties = app.activeDocument.findGrep (true);
for (var i = 0; i < empties.length; i++)
empties[i].parentTextFrames[0].remove()
}
function initprogressbar (stop, title)
{
progresswindow = new Window('palette', title);
progressbar = progresswindow.add ('progressbar', undefined, 1, stop);
progressbar.preferredSize = [200,20];
progresswindow.show ()
return progressbar;
}