1 Reply Latest reply on Mar 27, 2017 6:55 AM by jonase5228042

    Startup script that trigger on fontStyle Medium

    jonase5228042

      Hi there,

      I have a startup script that has been given to me by an earlier collegue of mine.

      I wonder if it's possible to change it to trigger only when fontStyle Medium are in the pasted frames?

      Now it seems that it slows Indesign down when pasting.

       

      #targetengine "texttvatt"
      
      main();
      function main() {
      var myPaste = app.menuActions.item("$ID/Paste");
      myPaste.addEventListener("afterInvoke", tvattMedium)
      var myPasteInPlace = app.menuActions.item("$ID/Paste in Place");
      myPasteInPlace.addEventListener("afterInvoke", tvattMedium)
      }
      function tvattMedium(){ 
      
      
      var myDoc = app.activeDocument;
      app.findTextPreferences = app.changeTextPreferences = null;  
      app.findTextPreferences.fontStyle = "Medium"; 
      app.activeDocument.pages.everyItem().pageItems.everyItem().locked = false;
      
      
      var mySearch = myDoc.findText(); 
      
      for(var i=mySearch.length-1; i>=0; i--){  
          var myStyle = mySearch[i].appliedParagraphStyle;  
          if(myStyle.fontStyle != "Medium")
      
      
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      
      
          try {
              app.findTextPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item("4 BODY");
              app.findTextPreferences.fontStyle = "Medium"
              app.changeTextPreferences.fontStyle = "Regular"
              }
              catch (myError) {}
      
      
          try {
              app.findTextPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item("4 BODY anfang fet");
              app.findTextPreferences.fontStyle = "Medium"
              app.changeTextPreferences.fontStyle = "Regular"
              myDoc.changeText(); 
              }
              catch (myError) {}
      
          try {
              app.findTextPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item("7 FAKTA recept body");
              app.findTextPreferences.fontStyle = "Medium"
              app.changeTextPreferences.fontStyle = "Regular"
              myDoc.changeText(); 
              }
              catch (myError) {}
      
          try {
              app.findTextPreferences.appliedParagraphStyle = myDoc.paragraphStyles.item("7 FAKTA text");
              app.findTextPreferences.fontStyle = "Medium"
              app.changeTextPreferences.fontStyle = "Regular"
              myDoc.changeText(); 
              }
              catch (myError) {}
      
      app.findTextPreferences = NothingEnum.nothing;
      app.changeTextPreferences = NothingEnum.nothing;
      
      
      }
      }