10 Replies Latest reply on Jul 27, 2016 12:15 PM by ProdMan

    script to set color for selected text

    ProdMan

      I am looking for a script I can write to set the color of selected text in a field (note: not all of the text in a field), which I can then link to a button. This is to make the process of changing some text in a field to a specific color much more efficient than selecting the text and then picking the color out of the color picker showing dozens of colors.
      There is a post from 2013 on this question, but the script suggested does not match the options I'm seeing in my version of FM Pro (v14 on Windows 10), so any updated response would be greatly appreciated.

        • 1. Re: script to set color for selected text
          mikebeargie

          Are you referring to this thread:

          Script to set color of selected text?

           

          If so all of the code and functions still look valid to me for FM14. What part are you having trouble with?

          • 2. Re: script to set color for selected text
            ProdMan

            Yes, that's the script.

            When I go to Script Workspace, new script, and choose "set variable", that opens a window that has three fields: Name, Value, Repetition. Value and Repetition have "Specify . . .", which opens up the calculation dialogue window.
            I've received one response which told me I should ignore the Value and Repetition fields for this issue, but I haven't a clue what to put in the Name field. Beyond that, the dialogue box doesn't look at all like the dialogue box showing in the example of the 2013 response: there is no place to simply set conditions and "if" statements, unless this is being done as a calculation. So that script isn't helping.

            • 3. Re: script to set color for selected text
              David Moyer

              Hi,

              please consider Conditional Formatting if you haven't already.  (In layout mode. right click on the object.)

              Addendum:

              Other than that, this custom function demonstrates the other functions you might use with the TextColor function:

              Capture.PNG

              • 4. Re: script to set color for selected text
                ProdMan

                I did try that before considering the button/script option. I set the condition that if the text began with "EP" it should be set to one color, if it began with "JM" it should be set to a different color. Nothing changed. So I eliminated the second condition. Still nothing changed. Then I read online that conditional formatting is extremely limited in its usefulness, and so began the button/script quest. If you know of a way to make the conditional formatting work I would love to hear it.

                • 5. Re: script to set color for selected text
                  David Moyer

                  like two messages passing in the ether ...

                  (for others, there's an edit to my original answer above).

                  • 6. Re: script to set color for selected text
                    mikebeargie

                    Using the image from the other thread (attached),

                     

                    On lines:

                     

                    1 - Name is "$select_size", value is "Get ( ActiveSelectionSize )", there is no modification to the default repetition.

                    6 - Name is "$select_start", value is "Get ( ActiveSelectionStart )", there is no modification to the default repetition.

                    7 - Name is "$content", value is "Get ( ActiveFieldContents )", there is no modification to the default repetition.

                     

                    You should read the documentation for the set variable script step:

                    FileMaker Pro 15 Help

                     

                    Note that the $name allows you to call that variable by name in the later calc on lines 8 & 9. a $name variable will clear automatically when the script is finished. A $$name variable is global, and will stay valid even after a script has finished, until the user closes the file. This is a local ($name) versus a global ($$name) variable.

                     

                    No need to worry about repetitions at all in this simple use case.

                    • 7. Re: script to set color for selected text
                      mikebeargie

                      Note that conditional formatting will apply to the entire text contents of a field. Whereas the script will change the color of just a selected portion of text.

                       

                      The script also works without context, meaning that it can be used for text highlighted in ANY field. Whereas conditional formatting needs to be applied on a per-object basis.

                      • 8. Re: script to set color for selected text
                        ProdMan

                        All very helpful; thank you. Just one question, really, before I begin to work this through: I notice that David's steps entail setting up a "custom function". A quick online check of "custom function Filemaker" specifies Filemaker Pro Advanced. I'm working in Filemaker Pro. Can I still do this?

                        • 9. Re: script to set color for selected text
                          David Moyer

                          Hi,

                          in the case that you had Advanced, you might find it a good thing to add to your CF library.

                          Otherwise, I was offering it as an example of three FM Get functions (that you have access to now).

                          Edit:

                          eesh - rereading it, it looks kind of snarky - not intended.

                          • 10. Re: script to set color for selected text
                            ProdMan

                            Thanks!. Will try the script option you suggest, since I don't want the entire field subjected to the color specification. Will post by tomorrow if I still have issues/questions. Thanks for all the help (and Mike and philmodjunk).