2 Replies Latest reply on Jul 1, 2018 7:02 AM by Ananth@desgin

    Adding Dropdown Feature for Paragraph Styles on Existing Script


      Hi, I need help with adding a drop-down feature to an existing script.


      The script below is meant to find the first instances of a Paragraph Style (H2) for a given reoccurring piece of copy and apply a different Paragraph Style to it (H1). It works fine for me since I can go into it and edit the paragraph style names, but I need to share it with a colleague who is not comfortable with scripting.


      If I can replace both instances where one chooses the paragraph styles with drop-down menus it would make this so much more user-friendly for him. Any thoughts on how to do it?




      // If you want the script to be un-doable, comment out the line above, and remove the comment from the line below
      // app.doScript(Main, undefined, undefined, UndoModes.ENTIRE_SCRIPT,"Run Script");
      function Main() {
      // Check to see whether any InDesign documents are open.
      // If no documents are open, display an error message.
      if (app.documents.length > 0) {
      var myDoc = app.activeDocument;
      var mStyle = myDoc.paragraphStyles.item("H2"); // edit this Paragraph Style currently applied to all instances of text
      var mStyle_1 = myDoc.paragraphStyles.item("H1"); // edit this Paragraph Style to applied to all FIRST instances of text
      var mFrames = myDoc.pages.everyItem().textFrames.everyItem().getElements();
      app.findTextPreferences = null;
      app.findTextPreferences.appliedParagraphStyle = mStyle;
      for (var k = 0; k < mFrames.length; k++)
          currFound = mFrames[k].findText();
          if (currFound.length > 0)
              currFound[0].paragraphs[0].appliedParagraphStyle = mStyle_1;
      app.findTextPreferences = null;
      alert("Finished applying Paragraph Style to 1st instances of previous paragraph style!");
      else {
      // No documents are open, so display an error message.
      alert("No InDesign documents are open. Please open a document and try again.")
        • 1. Re: Adding Dropdown Feature for Paragraph Styles on Existing Script
          Loic.Aigon Adobe Community Professional

          You could certainly build an UI with ScriptUI. See ScriptUI for Dummies from our dear friend Peter Kahrel

          ScriptUI for dummies | Peter Kahrel

          • 2. Re: Adding Dropdown Feature for Paragraph Styles on Existing Script
            Ananth@desgin Level 3


            Hope this helps you..


            var flag=0;  
            function findmytext()  
            var w = new Window ("dialog", "Apply Styles");  
            w.p1= w.add("panel", undefined, undefined, {borderStyle:"FONT"});     
            w.p1.add('statictext',undefined,"Select the find Paragraph Styles");   
            w.p1.g = w.p1.add('group');    
            w.p1.g.orientation = 'column'  
            w.p1.g.alignChildren = "center";  
            w.p2= w.add("panel", undefined, undefined, {borderStyle:"FONT"});     
            w.p2.add('statictext',undefined,"Select the change Paragraph Styles");   
            w.p2.g = w.p2.add('group');    
            w.p2.g.orientation = 'column'  
            w.p2.g.alignChildren = "center";  
            var Find_Pstyles=app.documents[0].paragraphStyles.everyItem().name;  
            var preset_list = w.p1.g.add ("dropdownlist", undefined, Find_Pstyles); 
            var Change_Pstyles=app.documents[0].paragraphStyles.everyItem().name;  
            var preset_list2 = w.p2.g.add ("dropdownlist", undefined, Change_Pstyles);  
            w.orientation = "column";  
            w.add ("button", undefined, "OK");  
            w.add ("button", undefined, "Cancel");  
            var myResult = w.show()   
            if(myResult == 1){  
                   if(flag==0) {alert("Please select the Correct Pstyles");}  
                else if (myResult== 2){  
             function mychanges(){  
            var myFindStyle=preset_list.selection.text;  
            var myChangeStyle=preset_list2.selection.text;  
            app.findGrepPreferences = app.changeGrepPreferences = null;  
            app.findGrepPreferences.appliedParagraphStyle =myFindStyle;    
            found = app.documents[0].findGrep();  
                for (i=0;i<found.length;i++) {    
                            app.changeGrepPreferences.appliedParagraphStyle = myChangeStyle;  




            Prabu G