16 Replies Latest reply on Mar 17, 2012 2:33 PM by Paul Riggott

    Reset foreground/background color values?

    Steven Mathisen

      Is there an equivalent command in scripting to reset the default color values to black/white or do you just script the value reset itself? Wasn't sure if there was an equivalent command to just hitting 'd' on the keyboard.

       

      Thanks!

        • 1. Re: Reset foreground/background color values?
          c.pfaffenbichler Level 9

          // =======================================================

          var idRset = charIDToTypeID( "Rset" );

              var desc1 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref1 = new ActionReference();

                  var idClr = charIDToTypeID( "Clr " );

                  var idClrs = charIDToTypeID( "Clrs" );

                  ref1.putProperty( idClr, idClrs );

              desc1.putReference( idnull, ref1 );

          executeAction( idRset, desc1, DialogModes.NO );

          • 2. Re: Reset foreground/background color values?
            JJMack Most Valuable Participant

            Steven if you do not understand the above code look up the scriptlistner plugin the ships with Photoshop it like an action recorder ther records script for events that can be redorded like "D".... When there is no script method to do something try using thet plugin to get code that can be used in your script.

            1 person found this helpful
            • 3. Re: Reset foreground/background color values?
              Muppet Mark Level 5

              There is a regular DOM method to this too… Both app.backgroundColor & app.foregroundColor are r/w access so you can create a new solid color and apply that…

              1 person found this helpful
              • 4. Re: Reset foreground/background color values?
                JJMack Most Valuable Participant

                In this case there is a DOM method to do one at a time. But as you know that will not always be the case.  I wrore a script to be use to save a restore colors to be used in actions so the action can change the colors the later restore them.

                /* ======================================================================================

                // 2009  John J. McAssey (JJMack)  http://www.mouseprints.net/

                // 

                // This script is supplied as is. It is provided as freeware.

                // The author accepts no liability for any problems arising from its use.

                //

                // This script is designed to be used by a Photoshop Action twice

                // A good pratice to use when creating an actions that use this scipt is for the action

                // not to do a save or play some other action between its two useages of this Script.

                //

                // The first time this script is used by an action Photoshops Current Forground

                // and Background Colors are saved into the document's meta-data Info Instructions field.

                //

                // The second time this script used by the action the script retreives what was

                // saved in the meta-data during the first usage and these colors are set.

                // and the saved data is removed from the document's meta-data Info Instructions field.

                //

                // ===================================================================================== */

                 

                /*

                <javascriptresource>

                <about>$$$/JavaScripts/SaveAndRestoreColors/About=JJMack's SaveAndRestoreColors.^r^rCopyright 2009 Mouseprints.^r^rRun twice script utility for action.^rNOTE:Don't play other actions between runs!^r^rFirst Run records Photoshops foreground and background swatch colors.^rSecond Run restores the recorded colors and removes the recording.</about>

                <category>JJMack's Action Run Twice Utility</category>

                </javascriptresource>

                */

                 

                if (app.documents.length > 0) {

                          if (app.activeDocument.info.instructions.indexOf("<Colorf>") == -1 ){ // no footprint fisrt useage

                                    //alert("first");

                                    // Retreive Document information for Foot Print

                                    saveforeColor = new SolidColor;

                                    saveforeColor.rgb.red = app.foregroundColor.rgb.red;

                                    saveforeColor.rgb.green = app.foregroundColor.rgb.green;

                                    saveforeColor.rgb.blue = app.foregroundColor.rgb.blue;

                 

                                    savebackColor = new SolidColor;

                                    savebackColor.rgb.red = app.backgroundColor.rgb.red;

                                    savebackColor.rgb.green = app.backgroundColor.rgb.green;

                                    savebackColor.rgb.blue = app.backgroundColor.rgb.blue;

                                

                                    // put footprint in metadata info instructions

                 

                                    app.activeDocument.info.instructions = app.activeDocument.info.instructions + "<Colorf>" + saveforeColor.rgb.red + "," + saveforeColor.rgb.green + "," + saveforeColor.rgb.blue + "</Colorf>" + "<Colorb>" + savebackColor.rgb.red + "," + savebackColor.rgb.green + "," + savebackColor.rgb.blue + "</Colorb>";

                                    //alert( "Saved ="  + "<Colorf>" + saveforeColor.rgb.red + "," + saveforeColor.rgb.green + "," + saveforeColor.rgb.blue + "</Colorf>" + "<Colorb>" + savebackColor.rgb.red + "," + savebackColor.rgb.green + "," + savebackColor.rgb.blue + "</Colorb>");

                   

                          }

                          else {

                                    //alert("second");

                 

                                    // Retreive saved information

                                    colorfOffset = app.activeDocument.info.instructions.indexOf("<Colorf>") + "<Colorf>".length;

                                    colorfLength = app.activeDocument.info.instructions.indexOf("</Colorf") -colorfOffset;

                                    saveforeColor = app.activeDocument.info.instructions.substr(colorfOffset, colorfLength);

                 

                                    colorbOffset = app.activeDocument.info.instructions.indexOf("<Colorb>") + "<Colorb>".length;

                                    colorbLength = app.activeDocument.info.instructions.indexOf("</Colorb") -colorbOffset;

                                    savebackColor = app.activeDocument.info.instructions.substr(colorbOffset, colorbLength);

                 

                                     //alert("Colorf = " + saveforeColor + " Colorb = " + savebackColor );

                 

                                    // Restore Colors

                 

                                    app.foregroundColor.rgb.red = saveforeColor.substr(0,saveforeColor.indexOf(","));

                                    saveforeColor = saveforeColor.substr(saveforeColor.indexOf(",") + 1,saveforeColor.length);

                                    app.foregroundColor.rgb.green = saveforeColor.substr(0,saveforeColor.indexOf(","));

                                    saveforeColor = saveforeColor.substr(saveforeColor.indexOf(",") + 1,saveforeColor.length);

                                    app.foregroundColor.rgb.blue = saveforeColor ;

                 

                                    app.backgroundColor.rgb.red = savebackColor.substr(0,savebackColor.indexOf(","));

                                    savebackColor = savebackColor.substr((savebackColor.indexOf(",") + 1),savebackColor.length);

                                    app.backgroundColor.rgb.green = savebackColor.substr(0,savebackColor.indexOf(","));

                                    savebackColor = savebackColor.substr(savebackColor.indexOf(",") + 1,savebackColor.length);

                                    app.backgroundColor.rgb.blue = savebackColor ;

                   

                                    // Remove footprint from metadata info instructions

                                    before = app.activeDocument.info.instructions.substr(0,app.activeDocument.info.instructions.indexO f("<Colorf>"));

                                    afterOffset = app.activeDocument.info.instructions.indexOf("</Colorb>") + "</Colorb>".length;

                                    after = app.activeDocument.info.instructions.substr(afterOffset, app.activeDocument.info.instructions.length - afterOffset);

                                    //alert ("before = " + before + " after = " + after);

                                    app.activeDocument.info.instructions = before + after;

                          }

                }

                else { alert("You must have at least one open document to run this script!"); }

                 

                1 person found this helpful
                • 5. Re: Reset foreground/background color values?
                  Steven Mathisen Level 1

                  That's great! I was wondering where the char to IDs came in; that I had been seeing in other example scripts.

                   

                  This might be an odd question but for runtime speeds is there a difference between scriptlistener, and an action called by a script? Wasn't sure if there were advantages over one to another as far as speed of execution. Thanks again for the help!

                  • 6. Re: Reset foreground/background color values?
                    JJMack Most Valuable Participant

                    Script and actions that do the same thing execition duration will most likely be nearly the same. Action may in some cases may be quicker,  For the script may contain logic to handle more document situations then an action without a script can handle. They can be programed to work where a strait action without a script would fail to work correctly or popup an error message.

                    • 7. Re: Reset foreground/background color values?
                      mariemario
                      if you do not understand the above code.

                      Whew, totally above my head and beyond my capabilities.

                      My default colors are white and black.

                      How did this happen?

                      Short of using the code above, isn't there some keys, key+combination I can do?

                      • 8. Re: Reset foreground/background color values?
                        Paul Riggott Level 6

                        As it says in the first post just use the letter d to reset.

                        • 9. Re: Reset foreground/background color values?
                          mariemario Level 1

                          when the fore-/background icon is white and black, pressing d doesn't change it to black and white.

                          • 10. Re: Reset foreground/background color values?
                            Paul Riggott Level 6

                            The letter d is the reset, to swap foreground/background use the x key.

                            • 11. Re: Reset foreground/background color values?
                              mariemario Level 1

                              OK, that works too, but when I press the d key, the white switches back to white

                              • 12. Re: Reset foreground/background color values?
                                Paul Riggott Level 6

                                d is the RESET key no matter what colours the foreground and background colours are d will reset them to Black/White. The x key toggles foreground/background colours.

                                • 13. Re: Reset foreground/background color values?
                                  mariemario Level 1

                                  OK, yes. RESET only goes to white/black. That is the problem. I've been living with it and can but it's a real hassle when working with masks and the like.

                                  • 14. Re: Reset foreground/background color values?
                                    Paul Riggott Level 6

                                    I don't understand? When working with masks you can use black or white brush and use the x key to toggle between white and black. What the difficulty with that?

                                    • 15. Re: Reset foreground/background color values?
                                      mariemario Level 1

                                      When I have my default (white/black), make a selection, add a layer mask, the selection, not the background is hidden. To get the selection to remain visible and the background hidden I have to invert the selection.

                                      Using the black or white brush does work the way I expect it to black hides, white reveals.

                                      • 16. Re: Reset foreground/background color values?
                                        Paul Riggott Level 6

                                        The foreground/background colours have nothing to do with how the mask is created! That's why I could not undersand you.

                                         

                                        You can always create your mask and use ctrl/i to invert the mask.