3 Replies Latest reply on Jul 30, 2013 3:29 AM by Andy_Bat1

    Passing arguments from Air to Photoshop jsx script

    ZdenekM

      I would like to invoke JavaScript file in Photoshop from my Adobe Air application. I managed to call my script with the following code:

       

      // Create native startup info

      nativeProcessStartupInfo = new NativeProcessStartupInfo();

      nativeProcessStartupInfo.executable = filePhotoshop; // File referencing Photoshop exe

      // Create Vector array to pass arguments

      procarg = new Vector.<String>();

      procarg.push("start");

      procarg.push(jsFileToCall);// String with path to my jsx file

      procarg.push(scriptData); // String with argument to pass to jsx file

      nativeProcessStartupInfo.arguments = procarg;

      // Create native process object for calling  executable file

      process = new NativeProcess();

      // SET ERROR HANDLERS

      process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA ,onError,false,0,true);

      process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR ,onError,false,0,true);

      process.addEventListener(IOErrorEvent.STANDARD_INPUT_IO_ERROR ,onError,false,0,true);

      process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR ,onError,false,0,true);

      process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA ,onError,false,0,true);

      // CALL NATIVE PROCESS

      process.start(nativeProcessStartupInfo);

       

      The Photoshop app is started, my JavaScript is invoked, but the argument is not passed into jsx.

       

      Is there any method how to pass arguments to script in Photoshop? (I know that I can use the file to pass the parameters, but I do not like that solution.)

       

      Thanks in advance for any hint.

       

      Zdenek M

        • 1. Re: Passing arguments from Air to Photoshop jsx script
          JJMack Most Valuable Participant

          The only documented way I know of is programming the script as a Photoshop Plug-in that has a dialog. Then record using the script in an action.  The script will record the arguments used in its dialog into the Photoshop Actions step.  Then when the action is used played the action recorded arguments are retrived and the script bypasses displaying its dialog. 

           

          However In CS3 I looked at Adobe Photoshop  Image Processor JavaScript it internaly used the Fit Image Plug-in Script and passed the width and hight to it. So it is posible to pass arguments from one JSX to an JSX Plug-in Script.

           

          From CS5 "Image Processor.jsx"

           

           

          // use the fit image automation plug-in to do this work for me

          function FitImage( inWidth, inHeight ) {

                    if ( inWidth == undefined || inHeight == undefined ) {

                              alert( strWidthAndHeight );

                              return;

                    }

                    var desc = new ActionDescriptor();

                    var unitPixels = charIDToTypeID( '#Pxl' );

                    desc.putUnitDouble( charIDToTypeID( 'Wdth' ), unitPixels, inWidth );

                    desc.putUnitDouble( charIDToTypeID( 'Hght' ), unitPixels, inHeight );

                    var runtimeEventID = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" );

                    executeAction( runtimeEventID, desc, DialogModes.NO );

          }

           

           

          If You can write a file from Adobe Air you could also write the jsx file to pass the args you want to pass a to plug-in script via the ActionManager.

          • 2. Re: Passing arguments from Air to Photoshop jsx script
            ZdenekM Level 1

            I solved my problem using Photoshop Connection SDK, which eables communication from Air to Photoshop CS5 using messages through TCP.

            I send the message with the following JavaScript from Air to Photoshop:

             

            $.setenv("parameter1","value1");

            $.setenv("parameter2","value2");

            $.evalFile("pathToMyJavaScriptFile.jsx");

             

            First two lines set parameters into environment variables, third line invokes my JavaScript file.

            Then I retrieve the parameters in my JavaScript file using $.getenv("parameter1"); function.

            • 3. Re: Passing arguments from Air to Photoshop jsx script
              Andy_Bat1 Level 1

              I want to protect my script, consider the option of on-line test of a certain number to be issued upon purchase. Could you write more in detail about the decision?