2 Replies Latest reply on Nov 16, 2015 2:20 AM by Kasyan Servetsky

    How to remove custom color in a Script UI control?

    Kasyan Servetsky Level 5

      Dear forum,

       

      I’m writing a script for batch renaming links in InDesign.

      1.jpg

      If the user types in the text edit field the new name which coincides with the original link’s name (the 1st static text in the group), the script gives a warning and paints it red.

      2.jpg

      3.jpg

      When the user corrects the issue by making the new name different, the script paints it black.

      15-11-2015 20-30-37.jpg

       

      Here’s where I got so far:

      g.et.onChange = function() {
          if (this.parent.children[0].text.replace(/\.[^\.]+$/, '') == this.text) {
              alert("\"" + this.text + "\" - the new name is the same as the old one! The file won't be renamed.", "Error", true);
              this.graphics.foregroundColor = this.graphics.newPen(this.graphics.PenType.SOLID_COLOR, [1, 0, 0], 1);
          }
          else {
              if (this.graphics.foregroundColor != undefined) {
                  $.writeln("Names are different: change the name from red to black.");                        
                  this.graphics.foregroundColor = this.graphics.newPen(this.graphics.PenType.SOLID_COLOR, [0, 0, 0], 1);
              }
          }
      }
      

       

      "g.et" is the edit text in a group.

      I wonder is there a way to reset the text’s color back to defaults instead of repainting it?

      Currently it checks if foregroundColor of graphics is not undefined – that is painted with “newPen” – and if it is true, paints it with black. But I suspect it’s a clumsy workaround and there should be a proper way to do this.

         

      Regards,

      Kasyan