4 Replies Latest reply on Jul 27, 2010 5:29 PM by Rand0mUser

    Simple beginner script problem

    Rand0mUser Level 1

      I'm reading Scripting InDesign CS3/4 with Javascript from O'Reilly and this simple example doesn't seem to work. Can someone please see what's up?

       

      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

      if (app.selection[0].parentStory.constructor.name!="Story")

      exit ( );

      // create an array of paragraphs by splitting the story on hard returns

      myArray = app.selection[0].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[0].parentStory.contents = myString;