Another useful application of split () and join () is processing paragraphs in a text frame. To see how this works, create a new InDesign document; draw a text frame big enough to hold about half a dozen names; and type a list of half a dozen names, one a line. Select the text frame or place the cursor somewhere in the list. The following script sorts the list alphabetically:
// check that a story is selected
exit ( );
// create an array of paragraphs by splitting the story on hard returns
myArray = app.selection.parentStory.contents.split ("\r");
// sort the array
myArray.sort ( );
// join the array as one string separated by hard returns
myString = myArray.join ("\r");
// replace the contents of the selected story with myString
app.selection.parentStory.contents = myString;
The code you posted should work as intended.
What do you see?
Edit: solution, I had to choose Adobe InDesign CS5 from the ESTK menu instead of ESTK CS5
Did you select some text?
It work, thanks