Good! — One thing left to do, here is a version that changes the last hard return into a Frame Break, or in case there is no return, adds the break.
Man I need to learn how to script.
Why not have a go thinking of something you'd like to script and see how far you get? The JS Guide over at Adobe's (InDesign section, “Scripting Stuff” button) has a lot of snippets for common tasks, so you can cut 'n' paste entire sections to make something new. And there always is the Adobe Scripting forum for the odd question left.
Anyway, here is the amended script. The changed section is around the “combine me with next” clause.
var combineMe = new Array;
for (a=0; a<app.selection.length; a++)
{
if (app.selection[a] instanceof TextFrame)
combineMe.push(app.selection[a]);
}
combineMe.sort (function (a,b) { return (a.geometricBounds[0] < b.geometricBounds[0]) || (a.geometricBounds[0] == b.geometricBounds[0] && a.geometricBounds[1] < b.geometricBounds[1]) ? -1 : 1; } );
for (a=0; a<combineMe.length-1; a++)
{
if (combineMe[a].nextTextFrame == null)
{
nextFree = a+1;
while (nextFree < combineMe.length && combineMe[nextFree].previousTextFrame != null)
nextFree++;
if (nextFree < combineMe.length)
{
// Add Frame Break when needed:
if (combineMe[a].characters[-1].contents != SpecialCharacters.FRAME_BREAK)
{
if (combineMe[a].characters[-1].contents == “r”)
combineMe[a].characters[-1].contents = SpecialCharacters.FRAME_BREAK;
else
combineMe[a].insertionPoints[-1].contents = SpecialCharacters.FRAME_BREAK;
}
combineMe[a].nextTextFrame = combineMe[nextFree];
}
}
}