13 Replies Latest reply on Jun 28, 2010 7:39 PM by JJMack

    Photoshop listener code is really....

    Ghoulfool Level 1

      Not a really important but technical question that's been bugging me: If photoshop can be coded in JavaScript, Visual Basic & Applescript what is the code from the script listener called (photoshop code? CS machine code?? Adobey Codey?)

        • 1. Re: Photoshop listener code is really....
          try67 MVP & Adobe Community Professional

          The listener creates both JS and VB code (each in a separate file, of course).


          • 2. Re: Photoshop listener code is really....
            Ghoulfool Level 1

            I know that - the asnswer is in the file name , but the nature of the code is very different to that scripted by hand, as it were.

            • 3. Re: Photoshop listener code is really....
              try67 MVP & Adobe Community Professional

              True, but it's still the same language, only using methods and properties

              which are not documented (or at least not properly documented) in the

              reference files.

              • 4. Re: Photoshop listener code is really....
                Michael L Hale Level 5

                try67 is rignt. Although most people refer to scriptlistner code as  something different, it is part of the DOM. It can be scripted 'by hand'. For example the function below will get the current tool. Code like that has to be written, you will not find it in the logs.

                function getCurrentTool()}
                   var ref = new ActionReference(); 
                   ref.putEnumerated( charIDToTypeID("capp"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") ); 
                   return = typeIDToStringID(executeActionGet(ref).getEnumerationType(stringIDToTypeID('tool')));
                }
                

                It is harder to work with than the rest of the DOM and it doesn't mix with the rest of the DOM. For example you could not use app in place of the putEnumerated line above.

                • 5. Re: Photoshop listener code is really....
                  JJMack Most Valuable Participant

                  Code generated by it is for the Action Manager there is no logic in the code recorded just like actions its step step step.... each step has hard coded parameters and a Action Manager Execution function.   The scriptlistner can record steps that can not be coded directly using Photoshop's Scripting Support.  However you can use the code generated by  it in Photoshop scripts to use the Action Manager Execution functions interface.  By using variables instead of the constants recorded and adding some logic you can create functions in Photoshop Scripts that are not possible using standard Photoshop scripting support. For example

                   

                  /* SetMarqueeSelection function from Scriptlistner plugin code

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

                  function setMarqueeSelection(x1, y1, x2, y2, type, shape, feather, antiAlias) {

                       var SelectionType =null;

                       if (type ==null)      {var SelectionType = "setd" }

                       if (type ==diminish)  {var SelectionType = "SbtF" }

                       if (type ==extend)    { var SelectionType = "AddT" }

                       if (type ==intersect) { var SelectionType = "IntW" }

                       if (type ==replace)   { var SelectionType = "setd" }

                   

                       var id3 = charIDToTypeID( SelectionType ); <----------------------------- type

                           var desc2 = new ActionDescriptor();

                           var id4 = charIDToTypeID( "null" );

                            var ref1 = new ActionReference();

                            var id5 = charIDToTypeID( "Chnl" );

                            var id6 = charIDToTypeID( "fsel" );

                            ref1.putProperty( id5, id6 );

                           desc2.putReference( id4, ref1 );

                           var id7 = charIDToTypeID( "T   " );

                            var desc3 = new ActionDescriptor();

                            var id8 = charIDToTypeID( "Top " );

                            var id9 = charIDToTypeID( "#Pxl" );

                            desc3.putUnitDouble( id8, id9, y1 );     <----------- Top

                            var id10 = charIDToTypeID( "Left" );

                            var id11 = charIDToTypeID( "#Pxl" );

                            desc3.putUnitDouble( id10, id11, x1 ); <----------- Left

                            var id12 = charIDToTypeID( "Btom" );

                            var id13 = charIDToTypeID( "#Pxl" );

                            desc3.putUnitDouble( id12, id13, y2 ); <--------------- Bottom

                            var id14 = charIDToTypeID( "Rght" );

                            var id15 = charIDToTypeID( "#Pxl" );

                            desc3.putUnitDouble( id14, id15, x2 ); <------------ Right

                           var id16 = charIDToTypeID( shape );            <------------- rectangle or oval

                           desc2.putObject( id7, id16, desc3 );

                           var id17 = charIDToTypeID( "Fthr" );

                           var id18 = charIDToTypeID( "#Pxl" );

                           desc2.putUnitDouble( id17, id18, feather ); <------------- 0 or number of pixels

                           var id19 = charIDToTypeID( "AntA" );

                           desc2.putBoolean( id19, antiAlias );          <----------- True or False

                       executeAction( id3, desc2, DialogModes.NO );

                  }

                  • 6. Re: Photoshop listener code is really....
                    Michael L Hale Level 5

                    JJMack wrote:

                     

                     

                    ...you can create functions in Photoshop Scripts that are not possible using standard Photoshop scripting support.

                    While that is true, you did not give a good example. You can make a marquee selection using the standard DOM.

                    app.activeDocument.selection.select([[40,400],[200,400],[200,600],[40,600]],SelectionType.REPLACE,0,false);
                    
                    • 7. Re: Photoshop listener code is really....
                      JJMack Most Valuable Participant

                      Michael L Hale wrote:

                       

                      JJMack wrote:

                       

                       

                      ...you can create functions in Photoshop Scripts that are not possible using standard Photoshop scripting support.

                      While that is true, you did not give a good example. You can make a marquee selection using the standard DOM.

                      app.activeDocument.selection.select([[40,400],[200,400],[200,600],[40,600]],SelectionType.REPLACE,0,false);
                      

                      Yes it is easy to make a selection using the standard api  app.activeDocument.selection.select(section array,selection type,feather,anti alias) it is not easy to duplicate the marquee selection tool for an aspect ratio elliptical selection. Perhaps with a strong mathematical and programming background one could come up with a function to create a seletion array of coordinates for an elliptical selection however for me it was much easier to install the plug-in and use the marquee tool a few times to get the code to use the Action Manager to create the aspect ratio elliptical or rectangle selection for me.

                      • 8. Re: Photoshop listener code is really....
                        Michael L Hale Level 5

                        You are right. I missed the shape argument in your function.

                        • 9. Re: Photoshop listener code is really....
                          JJMack Most Valuable Participant

                          Michael

                          I'm an old retired programmer that does not know Object programming classes DOM any of those newer programming things in fact I can't spell or type still i find I must do a little hacking from time to time to keep my mind working. In 2007 CS3 time frame I saw the Adobe's Fit-Image Plug-in was no longer a compiled program but was now a java script, plug-in support had been added to Photoshop scripting. At that time I was looking for a way a Photoshop Action could pass Parameters to a script.  I now had a way to do that so I Hacked the Fit Image script to do my thing. Of course Adobe changed the scripting plug-in support which broke my plug-in is CS4 I did not find this out till I upgraded from CS3 to CS5 here is a URL for my Aspect Ratio Selection plug-in script. http://www.mouseprints.net/old/dpr/AspectRatioSelection.jsx

                          • 10. Re: Photoshop listener code is really....
                            Michael L Hale Level 5

                            With just a quick look I don't think it is a good idea to use the same UUID as another script(Fit Image). You can get your own at http://www.famkruithof.net/uuid/uuidgen?typeReq=1

                             

                            The UUID is used to store the scirpts settings in customOptions, playbackParameters, or both. CustomOptions are stored in your Photoshop preference file. PlaybackParameters are stored in the acton that recorded the script/plug-in.

                             

                            When you use the same UUID you run the risk of breaking both your script and the one you got the UUID from.

                            • 11. Re: Photoshop listener code is really....
                              Muppet Mark-QAl63s Level 4

                              If you are on the mac OS then you could make your own with CS4+

                               

                              #target photoshop
                              
                              uuIDgen();
                              
                              function uuIDgen() {
                                   var uuID = undefined;
                                   var stdOut = '~/Documents/StdOut.txt';
                                   var sh = app.system('uuidgen > ' + stdOut);
                                   if (!sh) {
                                        var shText = new File(stdOut);
                                        shText.open('r');
                                        var uuID = shText.readln();
                                        shText.close();
                                        shText.remove();
                                   }
                                   return uuID;
                              }
                              

                              • 12. Re: Photoshop listener code is really....
                                Michael L Hale Level 5

                                There is also javascript functions that will generate a random( version 4 ) UUID. I just find it eaiser to go to the link I posted. You can get your choice of version 1 or 4 there.

                                • 13. Re: Photoshop listener code is really....
                                  JJMack Most Valuable Participant

                                  Michael L Hale wrote:

                                   

                                  With just a quick look I don't think it is a good idea to use the same UUID as another script(Fit Image). You can get your own at http://www.famkruithof.net/uuid/uuidgen?typeReq=1

                                   

                                  The UUID is used to store the scirpts settings in customOptions, playbackParameters, or both. CustomOptions are stored in your Photoshop preference file. PlaybackParameters are stored in the acton that recorded the script/plug-in.

                                   

                                  When you use the same UUID you run the risk of breaking both your script and the one you got the UUID from.

                                  I did not know  that code was uuid I did not use the same one I changed a number. Because of what they are I think it would be very unlikely that a UUID code generating site would dupe the code I used so I did not think it was worth the trouble to get my own UUID to use when I found out it was a UUID code....