Here's a quick-and-dirty script using various bits I found on these forums plus some of my own work. The script takes advantage of Script Labels to flag all text frames in a document where text import from file is desired. It also applies a style of your choosing to all paragraphs in the text frame after the file text is imported.
var myLabel = "SomeScriptLabel"; // Script label of frames you want to process (see Step 1)
var myStyle = "SomeParagraphStyle"; // Name of style you want applied
var document = app.documents.item(0);
var allTextFrames = toArray(document.textFrames);
var textFrames = selectWhere(myLabel, "label", allTextFrames);
var i = textFrames.length;
var attemptCounter = 0;
var successCounter = 0;
while (i--) {
if (textFrames.parentPage.appliedMaster) { // ignores master pages, as "appliedMaster" property will be null
attemptCounter++;
var myStory = textFrames.parentStory;
var newText = getFileContents(myStory.contents);
if (newText !== false) {
newText = newText.replace(/\n/g,"\r"); // OPTIONAL: replaces soft line breaks with "real" line breaks
myStory.contents = newText;
updateStyles(myStory);
successCounter++;
}
}
}
alert(successCounter + " of " + attemptCounter + " text frames updated");
function selectWhere(value, key, array){
var i = array.length; var t; var filtered = [];
while(i--){
t = array;
if(t && t[key] == value){
filtered.push(t);
}
}
return filtered;
}
function toArray(objects){
var i = objects.length; var array = [];
while(i--){
array.push(objects);
}
return array;
}
function getFileContents(filePath) {
filePath = filePath.split("\r");
var myTextFile = File(filePath[0]); // use only first line of frame contents as path
if (myTextFile.exists) {
myTextFile.open('r', undefined, undefined);
if (myTextFile !== '' && myTextFile !== null) {
var thisFileText = myTextFile.read();
myTextFile.close();
return thisFileText;
}
}
return false;
}
function updateStyles(myStory) {
for (var i=0; i < myStory.paragraphs.length; i++) {
var myParagraph = myStory.paragraphs;
myParagraph.appliedParagraphStyle = myStyle;
}
}