3 Replies Latest reply on Dec 5, 2014 2:13 PM by camilo umana

    How to adapt a Jongware's script for page numbers?

    camilo umana Level 1

      I have an index where

       

      Anne, 3, 5

      Mary, 11, 23-24

       

      and converted with the script (adding, for example +4)  does not affect hyphenated numbers:

       

      Anne, 7, 9

      Mary, 15, 27-24

       

      required: Mary, 15, 27-28


      I suposed that tagging the second hyphenated number with grep + character style could be a step but the script asks to select ALL the text.

      May be an idea to alter the script to run in a second step with those numbers considering colour or character style?


       

       

       

      //DESCRIPTION:omg the page numbers are all wrong!

      // A Jongware Script 18-Aug-2010

      if (app.documents.length == 0)

      {

           alert ("Oh give me some text to play with :'(");

           exit(0);

      }

      if (app.selection.length != 1)

      {

           alert ("We can't go on like this. Select some text first.");

           exit(0);

      }

       

      myDialog = app.dialogs.add ({name:"omg the numbers are wrong!",canCancel:true});

       

      with (myDialog)

      {

           with (dialogColumns.add())

           {

                with (dialogRows.add())

                     staticTexts.add ({staticLabel:"First to change"});

                with (dialogRows.add())

                     aBox = integerEditboxes.add({editContents:"1"});

                with (dialogRows.add())

                     staticTexts.add ({staticLabel:"Last to change"});

                with (dialogRows.add())

                     bBox = integerEditboxes.add({editContents:"99999"});

                with (dialogRows.add())

                     staticTexts.add ({staticLabel:"Add or subtract this value"});

                with (dialogRows.add())

                     cBox = integerEditboxes.add({editContents:"2"});

           }

      }

      if (!myDialog.show())

      {

           myDialog.destroy();

           exit(0);

      }

      first = aBox.editValue;

      last = bBox.editValue;

      step = cBox.editValue;

       

      if (first < 1 || first > last || step == 0)

      {

           alert ("Now you're pulling my nose arentya");

           exit(0);

      }

      app.findGrepPreferences = null;

      app.findGrepPreferences.findWhat = "\\b\\d+\\b";

      list = app.selection[0].findGrep(true);

      changes = 0;

      for (i=0; i<list.length; i++)

      {

           n = Number(list[i].contents);

           if (n >= first && n <= last)

                changes++, list[i].contents = String(n+step);

      }

      alert ("Number of changes: "+changes);