0 Replies Latest reply on Jul 22, 2009 4:25 PM by profeivan

    Change case of selected Style

    profeivan

      Hi, some time ago, I downloaded this useful script from Dave Saunders page.

       

      /DESCRIPTION: Converts text in designated parastyle to designated case

       

      if ((app.documents.length != 0) && (app.selection.length != 0)) {
          myDoc = app.activeDocument;
          myStyles = myDoc.paragraphStyles;
          myStringList = myStyles.everyItem().name;
          myCaseList = ["Uppercase","Lowercase", "Title case", "Sentence case"];
          myCases = [ChangecaseMode.uppercase, ChangecaseMode.lowercase, ChangecaseMode.titlecase, ChangecaseMode.sentencecase];

       

          var myDialog = app.dialogs.add({name:"Case Changer"})
          with(myDialog){
              with(dialogColumns.add()){
                  with (dialogRows.add()) {
                      with (dialogColumns.add()) {
                          staticTexts.add({staticLabel:"Paragraph Style:"});
                      }
                      with (dialogColumns.add()) {
                          myStyle = dropdowns.add({stringList:myStringList,selectedIndex:0,minWidth:133});
                      }
                  }
                  with (dialogRows.add()) {
                      with (dialogColumns.add()) {
                          staticTexts.add({staticLabel:"Change Case to:"});
                      }
                      with (dialogColumns.add()) {
                          myCase = dropdowns.add({stringList:myCaseList,selectedIndex:0,minWidth:133});
                      }
                  }
              }
          }
          var myResult = myDialog.show();
          if (myResult != true){
              // user clicked Cancel
              myDialog.destroy();
              errorExit();
          }
           theStyle = myStyle.selectedIndex;
           theCase = myCase.selectedIndex;
           myDialog.destroy();

       

           app.scriptPreferences.version= 5.0;  //app.scriptPreferences.version = 6.0; //
           app.changePreferences = null;
           myFinds = myDoc.search('',false,false,undefined,{appliedParagraphStyle:myStyles[theStyle]});
           myLim = myFinds.length;
           for (var j=0; myLim > j; j++) {
               myFinds[j].texts[0].changecase(myCases[theCase]);
           }

       

      } else {
          errorExit();
      }

       

      // +++++++ Functions Start Here +++++++++++++++++++++++

       

      function errorExit(message) {
          if (arguments.length > 0) {
              if (app.version != 3) { beep() } // CS2 includes beep() function.
              alert(message);
          }
          exit(); // CS exits with a beep; CS2 exits silently.
      }

       

      Now,in CS4 when I run the script, it reports this error:

       

      Error Number: 55
      Error String: Object does not support the property or method "changePreferences"
      Line: 42
      Source: app.changePreferences = null;
      interpreter: CS3 (5.0)

       

      I move the script to a folder named Version 5.0 but it doesn´t work.

       

      Any idea? thanks in advance!