11 Replies Latest reply on Aug 14, 2017 6:55 PM by Florent Caffarel

    Script - Modifying text path colors

    Florent Caffarel



      I'm trying to do something simple using a script but I can't find any solution anywhere.


      In my document there is a large bunch of very similar objects: circles with a text on path around them. I'd like to use a script to modify the color and stroke of the text all at once. I already know (kinda) how to loop through the selection but I don't know how to access the color of the text itself.


      Thanks !



        • 1. Re: Script - Modifying text path colors
          rob day Adobe Community Professional & MVP

          You should ask in the scripting forum. If you happen to be writing AppleScript something like this:


          tell application "Adobe InDesign CC 2014"

              set s to every story of active document

              repeat with x in s

                  set t to text containers of x

                  if class of item 1 of t is text path then

                      set p to parent story of item 1 of t

                      set fill color of p to "Your Swatch Name"

                  end if

              end repeat

          end tell

          • 2. Re: Script - Modifying text path colors
            smoothsea Level 3



            Do you actually need a script? If you have used paragraph or character styles then you should be able to do a global change on colour and stroke by changing the style.





            • 3. Re: Script - Modifying text path colors
              Laubender Adobe Community Professional & MVP

              Hi Florent,

              this thread was moved to the InDesign Scripting forum.


              Some questions about the scope you want to run your script on:


              Do you want to target all paths with text in a document?
              Or do you want to run it on a selection of page items?


              What is the version of your InDesign?
              What is your version of your operating system?



              • 4. Re: Script - Modifying text path colors
                Florent Caffarel Level 1



                Thanks for your answers.


                @ Smoothsea: yes, sadly I didn't use any paragraph or style so I'm stuck to a script I guess.


                @ Laubender: I want to target all paths in my selection. I select let's say 10 similar objects and would like to change all of them. Each object has only one text path.


                I'm using InDesign CS6 (v 8.0).


                I'm running a Mac OX 10.10.5


                Thanks !

                • 5. Re: Script - Modifying text path colors
                  S Hopkins Adobe Community Professional

                  Suggest you start getting used to paragraph styles. The following example script sets the properties for text for all selected text paths to a designated paragraph style ("Style1"). This way you can set the fill color, size, and whatever for the style as you want. And if you later change your mind, you can change the properties of the paragraph style. Of course, in the script you will need to change the reference to the application to CS6 as well as the name of the paragraph style you create.



                  tell application "Adobe InDesign CC 2017"

                    set parastyleRef to paragraph style "Style1" of document 1

                    set textPathList to every text path of selection

                    repeat with i from 1 to length of textPathList

                    set thisPath to item i of textPathList

                    set thisStory to parent story of thisPath

                    set textRef to object reference of paragraph 1 of thisStory

                    tell textRef to apply paragraph style using parastyleRef

                    end repeat

                  end tell

                  • 6. Re: Script - Modifying text path colors
                    Florent Caffarel Level 1



                    I use paragraphs and style...usually. For some reason, I didn't for these texts on paths.


                    As I'm also learning how to use scripting in ID, it's a good opportunity for me to understand how to reach this kind of object.


                    I'll try your solution, but it's not what I'm looking for in this particular case.





                    • 7. Re: Script - Modifying text path colors
                      Florent Caffarel Level 1

                      I stil have an issue though, if textpaths have a different color, then the paragaph style overwrites it.

                      • 8. Re: Script - Modifying text path colors
                        Laubender Adobe Community Professional & MVP

                        Hi Florent,

                        we have to be very precise when writing scripts. So I have to do some assumptions for some cases.

                        I assume that you want to:

                        1. Change the color of the text fill with a distinct color.

                        2. Change the stroke of the text with a distinct color.

                        3. Leave the color of the path alone.


                        You are working with a selection of objects on the page.

                        Some will have a text path, some will not.


                        More assumptions:

                        4. You want to change the color of a text stroke only, if a color is already applied.

                        5. Formatting of stroke weights and stroke colors of a given text on a path is uniform.
                        6. You do not want to change the stroke weight.

                        7. You do not want to change formatting of the first insertion point of a text path that contains no text.


                        Here a script snippet written in ExtendScript ( JavaScript ), that does this with objects that are not nested (are e.g. not part of a group or are anchored to text etc.pp.):


                        app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                            "Change Color of Text with Text Paths in Selection"
                        function changeColorOfTextWithTextPaths()
                            var newColorName = "NameOfColor";
                            var newColor = app.documents[0].colors.itemByName( newColorName );
                                var newColor = app.documents[0].colors.add
                                            name : newColorName ,
                                            colorValue : [ 0, 100 , 100 , 0 ] ,
                                            model : ColorModel.PROCESS ,
                                            space : ColorSpace.CMYK
                            var sel = app.selection;
                            var selLength = sel.length;
                            for(var n=0;n<selLength;n++)
                                if(sel[n].textPaths.length == 1)
                                    sel[n].textPaths[0].texts[0].fillColor = newColor ;
                                    // Assumption:
                                    // Leave text path with no text alone
                                    if(sel[n].textPaths[0].texts[0].insertionPoints.length < 2){ continue };
                                    // Assumptions:
                                    // 1. There is unique formatting with text strokes
                                    // 2. If color "None" is applied to the stroke do not change color
                                    if( sel[n].textPaths[0].texts[0].textStyleRanges[0].strokeColor.name != "None")
                                        sel[n].textPaths[0].texts[0].strokeColor = newColor ;


                        The script contains a single undo for all its actions. Change "NameOfColor" to the name of the color you want to use. If you don't a new color is added to your document and used. If you use a name that is not exactly the name of an existing color in your document a new color is added and used as well.


                        If I am wrong with any of my assumptions the script has to be rewritten.



                        1 person found this helpful
                        • 9. Re: Script - Modifying text path colors
                          Florent Caffarel Level 1

                          Hi, you're pretty much accurate on your assumptions


                          I actually need to change only the stroke around the letters. To put it simple, all the texts on paths have a fill color but no stroke, and it's not the same color everywhere. So I just need to add a stroke. The best would be to be able to do it across all documents in the book but I'll find how to do that


                          I'll text your script and will come back to you.



                          Thanks for the help everyone !

                          • 10. Re: Script - Modifying text path colors
                            Laubender Adobe Community Professional & MVP

                            Hi Florent,

                            if you do not want to change the fill color, just remove or comment out line 37 of my snippet.

                            If you want to add a stroke you have to supply at least two properties with values:





                            You could do it like that:

                            strokeWeight = 0.5

                            or explicitely with a unit value like that providing a string as value:

                            strokeWeight = "0.5pt"


                            Line 46 with the if statement and corresponding lines 47 and 49 should be removed or commented out if you want to provide a stroke with every text on all selected text paths.


                            Just add a new line of code before line 46 that is providing the stroke weight:

                            sel[n].textPaths[0].texts[0].strokeWeight = "0.5pt";


                            There are other properties that could be of interest like strokeAlignment.

                            See DOM documentation e.g. here:

                            Adobe InDesign CS6 (8.0) Object Model JS: Text




                            1 person found this helpful
                            • 11. Re: Script - Modifying text path colors
                              Florent Caffarel Level 1

                              Actually I replaced fillcolor with strokeColor in line 37 and added the other line as you said and it works fine.


                              Thanks a lot