10 Replies Latest reply on Jun 14, 2017 8:46 AM by Trevorׅ

    THEME_COLOR

    Dirk Becker Level 4

      Hi all,

       

      sorry for the cross posting from Illustrator Scripting, but this might be also interesting around here.

      The following works with InDesign and Illustrator.

       

      function main()
      {
        var palette = this.palette = new Window("""palette""");
        var graphics = palette.graphics;
        $.writeln("Brush:");
        var colors = ["background","disabledBackground","selection","focusRing"];
        while( colors.length ) {
          var name = colors.pop();
          $.writeln(name," = ",graphics.newBrush(graphics.BrushType.THEME_COLOR,name).color.toSource());
        }
        $.writeln();
      
        $.writeln("Pen:");
        var colors = ["foreground","disabledForeground","selection"];
        while( colors.length ) {
          var name = colors.pop();
          $.writeln(name," = ",graphics.newPen(graphics.PenType.THEME_COLOR,name,1).color.toSource());
        }
        $.writeln();
      }
      
      main();
      

       

      Regards,

      Dirk

        • 1. Re: THEME_COLOR
          Trevorׅ Adobe Community Professional

          Fantastic Dirk!, much better than the pathetic hacks we've been using for the past years, brilliant.

           

          Thanks

           

          Trevor

           

          P.s. not sure why you are using triple quotes and this

          var palette = this.palette = new Window("""palette""");

          and not

          var palette = new Window("palette"); 

           

          Any light on that?

          • 2. Re: THEME_COLOR
            Loic.Aigon Adobe Community Professional

            Nice !!

            • 3. Re: THEME_COLOR
              Dirk Becker Level 4

              > why triple quotes

               

              My sloppiness. That line was lifted from a member function in an Illustrator script where I used multi-line resource notation to build the palette and contained widgets. "this" stores the palette in my namespace object - AFAIK Illustrator only supports one target engine so I try to stay away from globals.

              2 people found this helpful
              • 4. Re: THEME_COLOR
                Trevorׅ Adobe Community Professional

                Actually there's at least 2 engines in Illustrator with "main" and "transient" being the standard ones.

                1 person found this helpful
                • 5. Re: THEME_COLOR
                  Laubender Adobe Community Professional & MVP

                  Hi Trevor,

                  I'm not so much into Illustrator scripting.


                  What is the version of AI where you  see this "transient" engine?
                  Currently I cannot check—I'm on a older OS X for developing a script for InDesign CS4 and have two different ESTKs open—where my ESTK that can target CS6 and CC is showing only "main" when connected to AI CC 17.1.0.

                   

                  Would "transient" work with the typical:

                  #targetengine "transient"
                  

                  statement?

                   

                  Thanks,
                  Uwe

                  • 6. Re: THEME_COLOR
                    Trevorׅ Adobe Community Professional

                    Hi Uwe

                     

                    Yes one would target it like that.

                    I don't know what's the difference between main and transient. It pitched up on my system in CC2015 and is still here for 2017.

                    I don't know why it's not showing up on yours.

                    Maybe it's connected to HTML panels I've done.

                     

                    When one creates an HTML panel it will create it's own workspace.

                    You can have

                    csInterface.evalScript("foo='bar'");

                    csInterface.evalScript("alert(foo)"); // bar

                     

                    but when you try foo from either the main or transient engines you get the undefined error.

                    On Illustrator the engines "invisible" which means you won't see it on the ESTK

                    I think by default in InDesign it's visible and you will see it.

                     

                    From the little I know about SDK when you create an engine you chose if you want the engine to be visible or not.

                     

                    Either way I can't but help repeat how impressed I am with Dirk's snippet, this problem has been going around the InDesign and Illustrator developers for years.

                    • 7. Re: THEME_COLOR
                      Laubender Adobe Community Professional & MVP

                      Trevorׅ  wrote

                      … Yes one would target it like that.

                      I don't know what's the difference between main and transient. It pitched up on my system in CC2015 and is still here for 2017.

                      I don't know why it's not showing up on yours.

                      Now, that I can explain. My old system is not able to run CC 2014, 2015 and 2017.

                       

                      And yes, Dirk always impresses me much!
                      I literally wasted hours over hours with Pen and Brush in ScriptUI before I discovered, that Dirk had a solution somewhere waiting on the web. So my big thanks go to Dirk!

                       

                      Regards,
                      Uwe

                      • 8. Re: THEME_COLOR
                        Dirk Becker Level 4

                        Uwe, Trevor,

                         

                        thanks, actually that solution was only posted yesterday.

                         

                        Some more notes:

                        The key list should be exhaustive for the palette widget of a current InDesign, but I did not yet dig into any other widgets or applications. As the list worked for Illustrator I also did not look for other/more values there.

                        My main motivation was to determine the current dark/bright UI setting in order to choose a matching icon, unfortunately I found no Illustrator equivalent to InDesign's app.generalPreferences.uiBrightnessPreference so I now check the background color value.

                        These theme colors are dynamic - always grab a new instances of the same brush or pen, the table is updated when the user adjusts the preference. Maybe we can catch those events with some custom draw widget?

                         

                        Dirk

                        • 9. Re: THEME_COLOR
                          Trevorׅ Adobe Community Professional

                          Hi Dirk,

                           

                          Events are very tough on Illustrator.

                          The only way that I can think of that might (15% ?) work on the jsx engine is using the archaic object "watch", linking it somehow to the brush object.

                          I once tried something like that but can't remember if I got it to work, although I think I might of I could very well be wrong (85% ?).

                           

                          Other than that if your out of the jsx engine which knowing you, you probably are then you could poll the property in an imitation of an idle event.

                           

                          In fact I just remembered that CSInterface.js has methods for retrieving UI skins info maybe those will be helpful.

                           

                          HTH

                           

                          Trevor

                          • 10. Re: THEME_COLOR
                            Trevorׅ Adobe Community Professional

                            line 477

                            CSInterface.THEME_COLOR_CHANGED_EVENT = "com.adobe.csxs.events.ThemeColorChanged";

                             

                            Looks promising