2 Replies Latest reply on Jul 18, 2011 6:13 AM by Trevorׅ

    Adding a colored character

    Trevorׅ Adobe Community Professional

      I would like a script for adding a colored character to the current cursor position.

      The script for add the character to the position I have courtesy of indesign secrets but I don't know how to specify the character color. (I don't want to chage the color of the rest of the text in the paragraph.

       

      if (app.selection[0].constructor.name == "InsertionPoint"){
          with (app.selection[0].insertionPoints[0]){ // insertion point
                      contents = String.fromCharCode(0x05B0); //
          }
      }

       

      What do I need to add for the color change.

       

      Thanks,

        • 1. Re: Adding a colored character
          Techi Panda Level 2

          Hi

           

          create one character style with your color. Sample i have created my character style name "arl"

           

          if (app.selection[0].constructor.name == "InsertionPoint"){
              with (app.selection[0].insertionPoints[0]){ // insertion point
                  app.selection[0].insertionPoints[0].appliedCharacterStyle ='arl';
                          contents = String.fromCharCode(0x05B0); //
              }
          }

           

          This will complete your task.

          1 person found this helpful
          • 2. Re: Adding a colored character
            Trevorׅ Adobe Community Professional

            Hi,

             

            Thanks a lot for your response, I had just workout that the following code works:

             

            app.selection[0].insertionPoints[0].fillColor = "C=20 M=70 Y=86 K=8";
            app.selection[0].insertionPoints[0].contents = String.fromCharCode(0x05B0);

             

            1) I am very interested why you added the lines, (I am a complete beginner at scripting and interested in learning better techniques)

                     if (app.selection[0].constructor.name == "InsertionPoint"){
                     with (app.selection[0].insertionPoints[0]){ // insertion point

             

            2) I would like to develop the script to check the the second character of the paragraph to see if it is CharCode(0x05B0) if it is not then I want to add (not replace) the character there.  If there is already a 0x05B0 there then I don't want anything to be added there.

             

            3) If the 0x05B0 is added the I would like to give it (only the one character) a XML tag to it so that it can be reformatted if the paragraph style late changes it's color.

             

            Will be most happy if I can do this,