10 Replies Latest reply on Feb 6, 2016 3:12 AM by c.pfaffenbichler

    Script to change color managent policies or to open files with "preserve profile"

    Lugiber28

      Hi!

      I'm trying to open filles with the "preserve profile" setting through my script.

       

      I don't really care if it's done with "openoptions" or by changing the RGB and CMYK color managent policies to "preserve profile". (Available through the menu Edit -> Color Settings.)

      I know this is possible through an action but I really need to change this through my script.

       

      I'm totally at a loss here so any pointers in the right direction would be very appreciated!

       

      Thanks!

       

      /Peter

        • 1. Re: Script to change color managent policies or to open files with "preserve profile"
          c.pfaffenbichler Level 9

          Does this help?

          // open file without mismatch warning:

          // 2015, use it at your own risk;

          #target photoshop

          var ref = new ActionReference();

          ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("colorSettings"));

          ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );

          var docDesc = executeActionGet(ref);

          var theOpenMismatch = docDesc.getObjectValue(stringIDToTypeID("colorSettings")).getBoolean(stringIDToTypeID("as kMismatchOpening"));

          alert (theOpenMismatch);

          // turn warning off;

          setMismatchOpening (false);

          // open file;

          app.open(new File(/* insert file’s path here*/));

          // restore setting;

          setMismatchOpening (theOpenMismatch);

          ////// change opening profile mismatch behaviour //////

          function setMismatchOpening (theBool) {

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

          var idsetd = charIDToTypeID( "setd" );

              var desc7 = new ActionDescriptor();

              var idnull = charIDToTypeID( "null" );

                  var ref2 = new ActionReference();

                  ref2.putProperty(charIDToTypeID( "Prpr" ), stringIDToTypeID( "colorSettings" ));

                  ref2.putEnumerated(charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));

              desc7.putReference( idnull, ref2 );

              var idT = charIDToTypeID( "T   " );

                  var desc8 = new ActionDescriptor();

                  var idaskMismatchOpening = stringIDToTypeID( "askMismatchOpening" );

                  desc8.putBoolean( idaskMismatchOpening, theBool );

              var idcolorSettings = stringIDToTypeID( "colorSettings" );

              desc7.putObject( idT, idcolorSettings, desc8 );

          executeAction( idsetd, desc7, DialogModes.NO );

          };

          • 2. Re: Script to change color managent policies or to open files with "preserve profile"
            Lugiber28 Level 1

            Thanks for helping out!

            I must admit that I don't understand every aspect of this script. But I'm getting the error "The requested property does not exist" on this line:

             

            var theOpenMismatch = docDesc.getObjectValue(stringIDToTypeID("colorSettings")).getBoolean(stringIDToTypeID("as kMismatchOpening"));

             

            Do you have any clues?

             

            /Peter

            • 3. Re: Script to change color managent policies or to open files with "preserve profile"
              c.pfaffenbichler Level 9

              Please remove the superfluous space in

              as kMismatchOpening
              • 4. Re: Script to change color managent policies or to open files with "preserve profile"
                Lugiber28 Level 1

                Thanks!

                I can't believe that I missed that. I'm horrible at finding typos!

                 

                I'm still having problems with your code though. It reports "true" wether the opened file contains a color profile or not, and all files are converted to my "Working RGB" (adobe rgb 1998).

                What I'm looking for is that the images should be opened with their current profile, so an sRGB image will be opened still in sRGB mode no matter which color profile is set as working rgb.

                 

                The idea is that the script will make better choices for color conversion than just "convert to current profile".

                 

                Again thanks for helping out!

                 

                /Peter

                • 5. Re: Script to change color managent policies or to open files with "preserve profile"
                  c.pfaffenbichler Level 9

                  Sorry, I overlooked a component … will try to amend the code.

                  • 6. Re: Script to change color managent policies or to open files with "preserve profile"
                    Lugiber28 Level 1

                    No problem!

                    I'm just happy that you're helping out!

                     

                    Thank you so much!

                     

                    I understand what the script does. It changes "Profiles Mismatches: Ask when opening".

                     

                    What I need is a script that changes "Color Management Policies" to

                     

                    RGB: Preserve embedded profiles

                    CMYK: Preserve embedded profiles

                    Gray: Preserve embedded profiles

                     

                    Hope I've made myself clear.

                    • 7. Re: Script to change color managent policies or to open files with "preserve profile"
                      c.pfaffenbichler Level 9

                      Try this, I actually only took RGB and CMYK into consideration but maybe you can amend it yourself.

                      // open file without mismatch warning:

                      // 2015, use it at your own risk;

                      #target photoshop

                      var ref = new ActionReference();

                      ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("colorSettings"));

                      ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

                      var docDesc = executeActionGet(ref);

                      var colorSetting = docDesc.getObjectValue(stringIDToTypeID("colorSettings"));

                      var theOpenMismatch = colorSetting.getBoolean(stringIDToTypeID( "askMismatchOpening" ));

                      var theRGBPolicy = colorSetting.getEnumerationValue(stringIDToTypeID("policyRGB"));

                      var theCMYKPolicy = colorSetting.getEnumerationValue(stringIDToTypeID("policyCMYK"));

                      alert (theRGBPolicy+"\n"+theCMYKPolicy);

                      // turn warning off;

                      setPolicy (stringIDToTypeID( "preserve" ), stringIDToTypeID( "preserve" ));

                      setMismatchOpening (false);

                      // open file;

                      app.open(new File("~/Desktop/VA13AHN_1.psd"));

                      // restore setting;

                      setPolicy (theRGBPolicy, theCMYKPolicy);

                      setMismatchOpening (theOpenMismatch);

                      ////// change opening profile mismatch behaviour //////

                      function setMismatchOpening (theBool) {

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

                      var idsetd = charIDToTypeID( "setd" );

                          var desc7 = new ActionDescriptor();

                          var idnull = charIDToTypeID( "null" );

                              var ref2 = new ActionReference();

                              ref2.putProperty(charIDToTypeID( "Prpr" ), stringIDToTypeID( "colorSettings" ));

                              ref2.putEnumerated(charIDToTypeID( "capp" ), charIDToTypeID( "Ordn" ), charIDToTypeID( "Trgt" ));

                          desc7.putReference( idnull, ref2 );

                          var idT = charIDToTypeID( "T   " );

                              var desc8 = new ActionDescriptor();

                              var idaskMismatchOpening = stringIDToTypeID( "askMismatchOpening" );

                              desc8.putBoolean( idaskMismatchOpening, theBool );

                          var idcolorSettings = stringIDToTypeID( "colorSettings" );

                          desc7.putObject( idT, idcolorSettings, desc8 );

                      executeAction( idsetd, desc7, DialogModes.NO );

                      };

                      ////// set policy //////

                      function setPolicy (rgb, cmyk) {

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

                      var idsetd = charIDToTypeID( "setd" );

                          var desc16 = new ActionDescriptor();

                          var idnull = charIDToTypeID( "null" );

                              var ref4 = new ActionReference();

                              ref4.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "colorSettings" ) );

                              ref4.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

                          desc16.putReference( idnull, ref4 );

                          var idT = charIDToTypeID( "T   " );

                              var desc17 = new ActionDescriptor();

                              var idpolicyRGB = stringIDToTypeID( "policyRGB" );

                              var idpolicy = stringIDToTypeID( "policy" );

                              desc17.putEnumerated( idpolicyRGB, idpolicy, rgb );

                              var idpolicyCMYK = stringIDToTypeID( "policyCMYK" );

                              desc17.putEnumerated( idpolicyCMYK, idpolicy, cmyk );

                          var idcolorSettings = stringIDToTypeID( "colorSettings" );

                          desc16.putObject( idT, idcolorSettings, desc17 );

                      executeAction( idsetd, desc16, DialogModes.NO );

                      };

                      • 8. Re: Script to change color managent policies or to open files with "preserve profile"
                        Lugiber28 Level 1

                        Thank you so much!

                        This works like a charm! I hope that I one day will learn to code this good!

                         

                        /Peter

                        • 9. Re: Script to change color managent policies or to open files with "preserve profile"
                          c.pfaffenbichler Level 9

                          Mainly it’s AM code recorded with ScriptingListener.plugin so not that much skill …

                          • 10. Re: Script to change color managent policies or to open files with "preserve profile"
                            c.pfaffenbichler Level 9

                            A somewhat cleaned up version:

                            // open file without mismatch warning and keep current color space:

                            // 2015, use it at your own risk;

                            #target photoshop

                            var ref = new ActionReference();

                            ref.putProperty(stringIDToTypeID("property"), stringIDToTypeID("colorSettings"));

                            ref.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

                            var docDesc = executeActionGet(ref);

                            var colorSetting = docDesc.getObjectValue(stringIDToTypeID("colorSettings"));

                            var theOpenMismatch = colorSetting.getBoolean(stringIDToTypeID("askMismatchOpening"));

                            var theRGBPolicy = colorSetting.getEnumerationValue(stringIDToTypeID("policyRGB"));

                            var theCMYKPolicy = colorSetting.getEnumerationValue(stringIDToTypeID("policyCMYK"));

                            var theGrayPolicy = colorSetting.getEnumerationValue(stringIDToTypeID("policyGray"));

                            // turn warning off;

                            var preserve = stringIDToTypeID( "preserve" );

                            setPolicy (preserve, preserve, preserve, false);

                            // open file;

                            app.open(new File("~/Desktop/VA13AHN_1.psd"));

                            // restore setting;

                            setPolicy (theRGBPolicy, theCMYKPolicy, theGrayPolicy, theOpenMismatch);

                            ////// set policy //////

                            function setPolicy (rgb, cmyk, gray, theBool) {

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

                            var idsetd = charIDToTypeID( "setd" );

                                var desc16 = new ActionDescriptor();

                                var idnull = charIDToTypeID( "null" );

                                    var ref4 = new ActionReference();

                                    ref4.putProperty( charIDToTypeID( "Prpr" ), stringIDToTypeID( "colorSettings" ) );

                                    ref4.putEnumerated(charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));

                                desc16.putReference( idnull, ref4 );

                                var idT = charIDToTypeID( "T   " );

                                    var desc17 = new ActionDescriptor();

                                    var idpolicyRGB = stringIDToTypeID( "policyRGB" );

                                    var idpolicy = stringIDToTypeID( "policy" );

                                    desc17.putEnumerated( idpolicyRGB, idpolicy, rgb );

                                    var idpolicyCMYK = stringIDToTypeID( "policyCMYK" );

                                    desc17.putEnumerated( idpolicyCMYK, idpolicy, cmyk );

                                    var idpolicyGray = stringIDToTypeID( "policyGray" );

                                    desc17.putEnumerated( idpolicyCMYK, idpolicy, gray );

                                    var idaskMismatchOpening = stringIDToTypeID( "askMismatchOpening" );

                                    desc17.putBoolean( idaskMismatchOpening, theBool );

                                var idcolorSettings = stringIDToTypeID( "colorSettings" );

                                desc16.putObject( idT, idcolorSettings, desc17 );

                            executeAction( idsetd, desc16, DialogModes.NO );

                            };