csInterface.evalScript return

I need to keep a back of jsx method use result .js

But if I do something like this:

var documentsLength = csInterface.evalScript ('app.documents.length');

the result is "undefined".

Someone knows how to do?

Thank you

We all do not seem to take advantage of the asynchronous nature of evalScript ;-)

The following works:

function clickHandler (evt) {
  var csInterface = new CSInterface(),
  docLength = undefined;
  csInterface.evalScript('app.documents.length', function (res) {
    docLength = res;
    alert(docLength);
  });
}

But as soon as you move the alert on recall of evalScript, it breaks:

function clickHandler (evt) {
  var csInterface = new CSInterface(),
  docLength = undefined;
  csInterface.evalScript('app.documents.length', function (res) {
    docLength = res;
  });
  alert(docLength);  // undefined
}

So either you put one inside a more complex JSX with other things you need, you rely on events or you enter the hell of reminder :-)

Concerning

Davide Barranca

---

www.davidebarranca.com

www.cs-extensions.com

Tags: Adobe

Similar Questions

  • CSInterface.evalScript reads the OLD of HTML data

    JS

    $("#browseBtn").click(function(){
        var field = $("#pathField");
        csInterface.evalScript("fileBrowser('*.txt')", function(result){
            field.val(result);
        });
        csInterface.evalScript("setMetadata('file_path', '" + field.val() + "')"); // Reads the old val and not the browsed val
    });
    

    The problem is that the second csInterface.evalScript does not appear to wait for the first update the entry on my UI (HTML) field. Instead, what is sent to my setMetadata() jsx-function is the OLD value. Why? EvalScript is asynchronous?

    $("#browseBtn").click(function(){
        var field = $("#pathField");
        csInterface.evalScript("fileBrowser('*.txt')", function(result){
            field.val(result);
            csInterface.evalScript("setMetadata('file_path', '" + field.val() + "')");
        });
    });
    
  • Value returned by the script JSFL in Javascript

    Hello all, please I need your help, I have a file called loader.js, and this is my code:

    var csi=new CSInterface(); 

    function evalScript(script, callback) {

    new CSInterface().evalScript(script, callback);

    }

    var docName = evalScript('fl.getDocumentDOM().name');

    alert(jsfl);

    I want the code to display the name of a document to a flash file, and I put it on a javascript file (to create an extension of html5 to Flash CC). Unfortunately, the variable docName showing always undefined . But if I change the code to be like this:

    var docName = evalScript('fl.trace(fl.getDocumentDOM().name);');

    The code above can make the variable docName showing my 'document name' inside in the flash IDE output panel. How can I get the name of the document and put it on the variable docName (if it's possible, I don't want to load any external jsfl file). Thanks for your help and sorry for my bad English,

    "recall" must be based, so you can write as below:

    (function () {
      'use strict';
      var csInterface = new CSInterface();
      function init() {
      $("#button").click(function () {
      csInterface.evalScript('function getNm(){return fl.getDocumentDOM().name;}getNm();', function(payload){
      alert("My documents name : "+ payload);
      });
      });
      }
      init();
    }());
    

    First arg of callback as JSFL function return value (string).

  • evalScript check null

    I use Adobe POC to make extensions of Photoshop.

    I'm having a problem searching for the null in my Javascript. Here is the code:

    (new CSInterface()).evalScript('$.getenv("RPC_PORT");', function(res) {
      if(res)
      {
          console.log("GOT THE RPC PORT: " + res);
      }
      else
      {
          console.log("NO RPC PORT");
      }
    });
    

    If the environment variable does not exist, res is null. The problem is the if statement does not work how it is supposed to. If res is null or not, he leads the party "GOT THE RPC PORT" of the if statement. So I'll get ' GOT THE RPC PORT: null ". How am I supposed to check this?

    Things are transferred through csInterface as a string, so then that res can be null, which comes through the chain spelling "null." Use either a string in your if statement or convert the result to the true null.

  • Pass data to jsx function returns the undefined value

    Probably a noob but question why I get defined during the passage of data to a jsx function?

    JavaScript

    var csInterface = new CSInterface();
    csInterface.evalScript ("myFunc ('ack')");

    ExtendScriptfunction

    {myFunc (property)}

    Alert ("connected myFunc get property value:" + property);

    }

    Things work fine if I just a life normal functionc everything without the passage of a variable.

    Found myself in the syntax

    csInterface.evalScript ("myFunc (" "+ ack +" ")");

  • How can I get the current state "onto the Pixels?

    Hello community,

    Here's the function that creates a switch that handles "snap to Pixels":

    index.html:

    <div id="STP_input" onclick="switchOnOff(this)">
         ...
    </div>
    

    main.js:

    $("#STP_input").click(function () {
         var a = switchOnOff(this);
         if (a) {
              csInterface.evalScript('switchSTP(true)');
         } else {
              csInterface.evalScript('switchSTP(false)');
         }
    });
    

    HostScript.jsx:

    function switchSTP(checkBTN) {
        'use strict';
        
        var condition;
        if (checkBTN === true) {
            condition = true;
        } else {
            condition = false;
        }
    
        var idsetd = charIDToTypeID( "setd" );
        var desc26 = new ActionDescriptor();
        var idnull = charIDToTypeID( "null" );
            var ref6 = new ActionReference();
            var idPrpr = charIDToTypeID( "Prpr" );
            var idtoolsPreferences = stringIDToTypeID( "toolsPreferences" );
            ref6.putProperty( idPrpr, idtoolsPreferences );
            var idcapp = charIDToTypeID( "capp" );
            var idOrdn = charIDToTypeID( "Ordn" );
            var idTrgt = charIDToTypeID( "Trgt" );
            ref6.putEnumerated( idcapp, idOrdn, idTrgt );
        desc26.putReference( idnull, ref6 );
        var idT = charIDToTypeID( "T   " );
            var desc27 = new ActionDescriptor();
            var idtransformsSnapToPixels = stringIDToTypeID( "transformsSnapToPixels" );
            desc27.putBoolean( idtransformsSnapToPixels, condition );
        var idtoolsPreferences = stringIDToTypeID( "toolsPreferences" );
        desc26.putObject( idT, idtoolsPreferences, desc27 );
        executeAction( idsetd, desc26, DialogModes.NO );
    
        return;
    }
    

    But when I hide the Panel and show once again, that the switch back to the default state, turn on my Panel, not "hook to Pixels" PS settings setting. Is it possible to get the current status 'Hang the pixels' setting? How?

    Best regards.

    See post 8 in this thread:

    Re: Need someone to update or create script: "snap to grid of pixels.

  • Download file with NodeJS extension CEP

    I try to get the download file with NodeJS working in my CEP for first Pro CC 2015 extension. I have the following script:

    var http = require('http');
    var fs = require('fs');
    var file = fs.createWriteStream("file.jpg");
    var request = http.get("http://i3.ytimg.com/vi/J---aiyznGQ/mqdefault.jpg", function(response) {
        response.pipe(file);
    });
    
    
    

    The script works perfectly fine if I run it on his own. For example, if I put in a file named test.jsand run test.js node in the terminal, it registers with success the image in the same directory that the script is in.

    When I include in my CEP extension, however, nothing happens. The script runs without error, but no file is downloaded anywhere. Even if I try:

    try {
         response.pipe(file);
         alert("File downloaded");
    } catch(e) {
         alert(e);
    }
    

    The "Download file" alert appears. If lack-of-download does not seem to come from an error in the code, but maybe how CEP works itself? I am at a loss. Any suggestions?

    Thank you!

    For anyone interested, I came up with a solution.

    Instead of recording in the extension directory, you can save a file downloaded in the path of the project, using app.project.path. Here is my commented code:

    In hostscript.jsx

    function returnPath() {
         var projectPath = app.project.path;
         // split the path into an array
         var parsed = projectPath.split("/");
         // remove the last element (which is the name of the Premiere project file)
         parsed.pop();
         // rejoin the array, giving the parent directory of the Premiere project file
         var joined = parsed.join("/");
         return(joined);
    }
    

    In main.js

    function downloadAndImport(url, songName) {
         // call the evalScript we made in the jsx file
         csInterface.evalScript('returnPath()', function(result) {
              var https = require('https');
              var fs = require('fs');
              var mkdirp = require('mkdirp');
              // create a Downloads directory in the project path if it doesn't exist already
              var downloadDirectory = result + '/Downloads';
              mkdirp(downloadDirectory, function(err){
                   if (err) { // handle error }
              });
              var fullPath = downloadDirectory + "/" + songName;
              var file = fs.createWriteStream(fullPath);
              var request = https.get(url, function(response) {
                   response.pipe(file);
                   // ensure file is complete before importing
                   response.on('end', function() {
                        csInterface.evalScript("app.project.importFiles(['" + fullPath + "'])");
                   });
             });
         });
    }
    

    It works for my needs. I hope it helps someone else!

  • How to properly interact with script files?

    Hi all .

    I want to make sure that after a treatment in the script changed State of control elements (buttons, input fields). But access to the Properties something got only in main.js. Et treatment in most will be in the file hostscript. jsx .

    For example, btn_test1 does not show Properties, and btn_test1 Watch. How to interact with js files and How to access the properties of objects in the resource file hostscript. jsx

    Edraw Mind Map (Free Version) - ww1.jpg

    Thanks for the quick response. I found a solution... Jsx file returns 'result' = button name blocked, which is applied to the element. For a single key, just for a few - have need to pass an array

    HTML

    JS

    $("#btn_test1").click (function () {}

    csInterface.evalScript ('sayHello ()', {function (result)})

    document.getElementById ("result") .disabled = true;

    });

    JSX

    function SayHello () {}

    Return ("btn_test2");

    }

  • Event trigger when HTML5 Extension Panel collapsed on Flash CC

    Hi all, I'm just curious to know if it is possible to call a function when the Panel collapses? I have a function to display all items in the library, it's works fine if I only works in a single document, but if I worked on another document (while the other is open), the Panel displays items from the last I worked, if I close the cover and reload it again, it shows the elements in the current document. How can I call a function that can show the correct items while I move from a document, one of your suggestion will really help, thank you, and sorry for my bad English.

    We can hear selectionChange notifier to modify the document as below:

    (function () {
      'use strict';
      var csInterface = new CSInterface();
      var activeDoc = "";
      csInterface.evalScript('function getNm(){try{return fl.getDocumentDOM().name;}catch(e){return null};getNm();}',
      function(payloads){
      if (payloads!=null) activeDoc = payloads;
      }
      );
    
      function init() {
      csInterface.addEventListener(
      "com.adobe.events.flash.selectionChanged",
      function(ev) {
      csInterface.evalScript('function getNm(){return fl.getDocumentDOM().name;}getNm();', function(payloads){
      if (activeDoc!=payloads){
      alert("Callback from host : "+ payloads);
      activeDoc = payloads;
      }
      });
      });
      }
      init();
    }());
    
  • onClick event work not when you try to open an image in Photoshop CC2015 extension Panel

    Hello

    I am writing an extension for CC2015 which opens a panel containing the tab page layouts and a few buttons.

    I want the buttons to perform a function onClick that opens a PNG file in Photoshop, but I can't seem to get this function to work as expected.

    The main parts of my index.html for the extension that defines one of the buttons is:

    < button class = "CLASS BUTTON" id = "ID of the BUTTON" role = "BUTTON" > BUTTON NAME < / button >

    I then added a function to the event listener for the button (see below) who works on the search for the name of the id of the button:

    < script type = "text/javascript" >

    document.getElementById('BUTTON_ID').addEventListener ("click", onClickButton, false);

    function onClickButton()

    {

    var imageFile = new File("C:/FOLDER/FILENAME.png");

    docRef = app.open (imageFile);

    }

    < /script >

    This piece of Javascript above falls in this part here:

    {

    imageFile var = new File ("FILENAME.png");

    docRef = app.open (imageFile);

    }

    For some reason any image does not open the button click on with the bit above the script, but if I run this code snippet in isolation by running the following in the ESTK the PNG file opens perfectly fine in Photoshop

    #target photoshop

    imageFile var = new File ("FILENAME.png");

    docRef = app.open (imageFile);

    I tested the event listener and the onClick and everything seems to be fine here because if I replace the part app.open of the script with a simple alert illustrated under the button returns a new window with the current alert text:

    < script type = "text/javascript" >

    document.getElementById('BUTTON_ID').addEventListener ("click", onClickButton, false);

    function onClickButton()

    {

    Alert ("you pressed me");

    }

    < /script >

    If anyone has information as to where I have gone wrong here it would be great that I don't immediately see the wood for the trees.

    Thank you.

    Hi Chris,

    you mix JSX and JS, and it won't work.

    The Virtual Machine that interprets JS is the Google V8 engine, belonging to the CEF (integrated framework chrome - the HTML group container).

    The Virtual Machine that interprets JSX (Extendscript) belongs to Photoshop.

    If you say that the V8 "app.open (imageFile)" he has simply not understand.

    JSX code should belong to the JSX file, like:

    function openImage(imageName){
        app.open(new File(imageName));
    }
    

    and in the JS, you need to:

    function onClickButton() {
      var csInterface = new CSInterface();
      csInterface.evalScript("openImage('C:/FOLDER/FILENAME.png')", function(res) { console.log(res); }
    }
    

    I hope this helps.

    Davide Barranca

    ---

    www.davidebarranca.com

    www.cs-extensions.com

  • What is the difference between the 4 CEP and cep 5? It is events of photoshop works in cep 4 photohsop cc 2014?

    I am listening a Photoshop to html table events by referring to this link HTML panels tips: Photoshop #8 events, take 2 | Photoshop, etc. but it does not "Script eval error." I use Photoshop cc 2014 and 4 CEPServiceManager in 64-bit windows 7.

    In my index.html page contains

    <! doctype html >

    < html >

    < head >

    < meta charset = "utf-8" >

    < link id = "hostStyle" rel = "stylesheet" href="css/theme.css"/ >

    < id link = 'theme' rel = "stylesheet" href="css/light.css"/ >

    < title > < / title >

    < / head >

    < body onload = "onLoaded ()" >

    < div style = "width: 80%;" "auto margin: 0" >

    < h3 class = "center" > PS events < / h3 >

    < class label = "finish-switch layer" >

    < Input id = 'registerEvent' type = "checkbox" class = "layer of finish-switch__input" >

    < div class = "layer of finish-switch__toggle" > < / div >

    < / label >

    < input type = "text" id = 'result' class = "finish-text-input layer" style = "" margin-left: 10px "placeholder value =" listen to events of "=" ">"

    < / div >

    "< script src="js/libs/CSInterface-4.0.0.js "> < / script >

    "< script src="js/libs/ps_host_adapter-2.0.js "> < / script >

    "< script src="js/libs/jquery-2.0.2.min.js "> < / script >

    < script src = "js/themeManager.js" > < / script >

    < script src = "js/main.js" > < / script >

    < script src = "js/ext.js" > < / script >

    < / body >

    < / html >

    My main.js file:

    (function () {}

    "use strict";

    var csInterface = new CSInterface();

    function Register (inOn) {}

    Ps_host_adapter events - 2.0.js

    PSEvent.CUT = "1668641824";

    PSEvent.COPY = "1668247673";

    PSEvent.PASTE = "1885434740";

    If (inOn) {}

    PSEventAdapter.getInstance () .addEventListener (PSEvent.CUT, PSCallback);

    PSEventAdapter.getInstance () .addEventListener (PSEvent.COPY, PSCallback);

    PSEventAdapter.getInstance () .addEventListener (PSEvent.PASTE, PSCallback);

    } else {}

    PSEventAdapter.getInstance () .removeEventListener (PSEvent.CUT, PSCallback);

    PSEventAdapter.getInstance () .removeEventListener (PSEvent.COPY, PSCallback);

    PSEventAdapter.getInstance () .removeEventListener (PSEvent.PASTE, PSCallback);

    }

    }

    function init() {}

    themeManager.init ();

    {$('#registerEvent').change (function ()}

    Register ($(this).is(':checked'));))

    });

    }

    function PSCallback (csEvent) {}

    Send to JSX convert typeid in stringIDs

    csInterface.evalScript ('convertTypeID (' + JSON.stringify (csEvent.type) + ' ')', function (res) {', {(res) function}})

    $('#result').val (res.toString ());

    });

    }

    init();

    }());

    And. JSX file is

    PSEventAdapter.getInstance () .addEventListener (PSEvent.ROTATE, handleEvent);

    private void handleEvent(event:PSEvent):void

    {

    Handle the event rotation

    }

    one please send me project to extend photoshop example html5 for event listener

    Yes you are right, but I tried that also I don't get

    jsx is:

    function convertTypeID (tID) {}

    Return typeIDToStringID (Number (tID));

    }

    This also do not listen to all the events.

  • How can I find the aim or the result of an event of photoshop?

    Hi all

    Is there a method of extracting information about the results of a trial of Photoshop? For example, after can a delete event ("Dlt") I get any information on what has been deleted?

    Specifically, my current needs are to find which layer has been removed after a delete event.

    The relevant js in my project code is:

    function registerPSEvent( typeIDs, clear ){
      // unregisters an even before adding it - prevents double events
      var regUnreg = null;
      if( clear ){
      console.log( 'Unregistering ' + typeIDs );
      regUnreg = 'PhotoshopUnRegisterEvent';
      } else {
      console.log( 'Registering ' + typeIDs );
      regUnreg = 'PhotoshopRegisterEvent';
      }
    
      var e = new CSEvent(
      'com.adobe.' + regUnreg,
      'APPLICATION',
      csInterface.getApplicationID(),
      csInterface.getExtensionID()
      );
      e.data = typeIDs;
      csInterface.dispatchEvent(e);
    }
    
    // s2t is simply an abbreviation of stringIDToTypeID
    function addPSEventListener( typeStrings, callback, target ) {
      csInterface.evalScript( "s2t('"+typeStrings+"')", function(r){
      registerPSEvent( r, true );
      registerPSEvent( r );
      csInterface.addEventListener( 'PhotoshopCallback', callback.bind(target) );
      } );
    }
    
    addPSEventListener( 'delete', delLayerEventHandler, this );
    
    delLayerEventHandler = function(e) {
      console.log(e);
      // here i would like to be able to get what was deleted
    }
    
    

    Thank you

    Tom

    I just discovered that, when an event is received event.data holds 2 ints.

    I thought that these 2 numbers were due to me using stringIDToTypeID rather than charIDToTypeID. However, the second number is a way to access all the attributes of the event. So I now use the function below to get info about the event:

    function get_event_descriptor (id) {}

    var / / desc = new ActionDescriptor();

    try {}

    desc.fromID (id);

    Aref var = desc.getReference (s2t ('null'));

    var aref_obj = {}

    DCLASS: t2s (aref.getDesiredClass (s2t ('null'))),

    name: aref.getName (),.

    ID: aref.getContainer () .getName)

    };

    return JSON.stringify (aref_obj);

    } catch (e) {}

    Returns false;

    return JSON.stringify (e.message);

    }

    }

    ID is the 2nd int returned in event.data.

    Currently, I just dug around enough to make sure that the class of event parameter is returned correctly but cela is sufficient for my current needs.

  • Simultaneity of script

    The fact that csInterface.evalScript (foo, callback) is asynchronous in regard to obtaining the recall and evalScript also average return overall value is asynchronous? I.e. If I call evalScript for two scripts, it is possible to get them working on simultaneously. There doesn't seem to be the case and certainly not something that Photoshop is likely to support, but it is part of my code to manage, i.e. ensure callback triggered before calling the next evalScript? Or CEP-layer manages that for example by stuff of queues?

    IIRC it is asynchronous. You'll need nesting evalScripts in order to ensure that they execute in order.

    example:

    csInterface.evalScript ('foo ()', {function (result)})

    csInterface.evalScript ('bar ()', {function (result)}

    });

    });

  • HTML extensions: getting values of reminders

    I want to store a value JSX in JS, so I must not call evalScript all the time.

    Is there a way to get a value on a reminder like that?

            var csInterface = new CSInterface();
         evalout = "lcl";
              
         csInterface.evalScript("$._ext_PPRO.testOnLoadedVar",
         function (result)
              {
              evalout = result;
              console.log("In testcb: evalout:"+evalout);
              console.log("In testcb: result:"+result);
              }
         );
         console.log("evalout: "+evalout);
    

    The console output occurs before the callback, then evalout is equal to "lcl". I also tried the function as a named function, but the same thing happens. I think that there is something basic that I'm missing.

    Thank you

    Miles

    See onLoaded() in the current example of PProPanel; It returns data from ExtendScript, JavaScript.

    https://github.com/Adobe-CEP/samples/tree/master/PProPanel

  • updated the .jsx file variable

    Lets say I have file1.js and it has a variable inside of her x.  and I have a .jsx file which executes a within Photoshop.  Is it possible that at the end of the operation inside the .jsx file can I have change the variable x in my .js file?

    -TIm

    Here is an example of js code:

    (function () {}

    "use strict";

    var csInterface = new CSInterface();

    var result;

    function init() {}

    themeManager.init ();

    $("#doJSX").click (function () {}

    csInterface.evalScript ('extendscriptFunction ()',

    {function (CB)}

    result = cb;

    });

    });

    }

    init();

    }());

    Function evalScript has two args, arg 1 cru Extendscript depends on, 2nd arg is callback as sample of return.

    We can get the back using the callback function.

    Ten

Maybe you are looking for

  • My iPhone 6 s write always full memory

    I have iPhone 6s and Hi write memory is full. I probe some clearing, memory... Soft, restart...  Nothing help. What s wrong?

  • Airport Extreme &amp; Motorola Surfboard SB6121

    I get a flashing red light on surfboard when connecting to the extreme and internet connection sometimes drops, but I get a blue light flashing on surfboard, when it connects directly to the iMac with ethernet cable.  Any thoughts?

  • Why Console see the place on my Dock

    I had a few problems scanning via WiFi but I have not tried any diagnosis. Suddenly, a black box with yellow writing appeared on my dock and it won't go away. She seems to have 4,000 messages, none of which I understand. My computer is under attack?

  • Re: Satellite A100 - cannot get video off the LCD screen

    Hi, I'm fixing a Satellite A100 for someone. I can't get the video on the LCD display, an external monitor, either the s-video port.The system turns on and you hear the fans from the looks of the lights, the HDD seems to start windows.I reinstalled t

  • Forget the Bios password

    Please help... I forgot my bios password My laptop Hp Pavilion dm1 System disabled Code: 76110508