2 Replies Latest reply on Jun 23, 2017 4:00 PM by Naoki-Hada

    [Q] CEP plugin response issue when Illustrator is in background. Any solution?

    Naoki-Hada Level 1



      This is refined question with minimized issue code from following.

      [Q] Illustrator seems forgeting what selected after 50 sec on Mac. How to avoid?


      It happens only on background about 1-2 times in 1 minutes.

      Regularly evalScript() takes 20-50 ms, but it got slow 2-5 sec.

      It's like stop breathing in sleep.


      While this stop breathing happening, bring Illustrator back on foreground and

      do massive number of evalScript() call made, it become almost does not responds at all.

      It's like a heart attack.


      When the heart attack happened, the cure is call $.gc() from ExtendScript Tool Kit.

      So following code has $.gc() included, but it seems not working from CEP code.


      It might be related with following

      Re: ID CC 2014 plus ExtendScript (Yosemite) slow to the point of not working...


      The solution may not work as current code is targeting end user environment.

      But if we can identified bottle neck process, we may be able to do something.


      So is there any way we can do to prevent above stop breathing issue?

      I think it could be minor issue, but it may lead to the heart attack issue.



      pollCounter = 319 is issue.

      every 1 sec polling.


      Screen Shot 2017-06-22 at 8.44.58 AM.png


      pollCounter = 201 and 212 has issue.


      Screen Shot 2017-06-22 at 8.42.48 AM.png


      Test code is from modified from following.


      CEP-Resources/CEP_7.x/Samples/CEP_HTML_Invisible_Extension-7.0 at master · Adobe-CEP/CEP-Resources · GitHub


      Modified part in index.html





      var illustrator = null;



      var pollCounter = 0; // for throttling

      var pollVariable = null;



      var csi = new CSInterface();



      function AiSupport(enabled) {

          this.inPoll    = false; // waiting for poll() response

          this.isMac     = (navigator.platform == "MacIntel");








      window.onload = function() {





      var host = csi.getHostEnvironment();



          if (host.appId == "ILST") {

              loadJSX("AiActionsTest.jsx"); // min version

              illustrator = new AiSupport(false);




          pollVariable = setInterval(function() {


           // }, 100); // 100ms

           }, 1000); // 1000ms






      window.onunload = function() {








      function loadJSX(fileName) {

          var csInterface = new CSInterface();

          var extensionRoot = csInterface.getSystemPath(SystemPath.EXTENSION) + "/jsx/";

          csInterface.evalScript('$.evalFile("' + extensionRoot + fileName + '")');




      function poll() {









      function pollAi() {

          if (AiSupport.inPoll) {

              console.log('pollAi(): Skip to avoid duplicate request');

          } else {

              AiSupport.inPoll = true;

              console.log("pollAi(): getCurrentTool() request: pollCounter=", pollCounter);

              console.time("pollAi"); // performance measurement (NodeJs)

              csi.evalScript("aiGetSelectionType()", function (response) { // bypass for performance

                  console.timeEnd("pollAi"); // performance measurement (NodeJs)

               console.log('response = ' + response);



                  // other business logic



                  AiSupport.inPoll = false;






      function gcAi() {


          console.time("gcAi"); // performance measurement (NodeJs)

          csi.evalScript("$.gc()", function (response) {

              console.timeEnd("gcAi"); // performance measurement (NodeJs)








      // return selection data type

      function aiGetSelectionType(){

          // $.writeln("aiGetSelectionType()"); // debug only

          $.hiresTimer; // reset

          $.gc(); // Garbage collector

          var result = "Unsupported";



                  var _sel = activeDocument.selection; // TextRange when Text chars are selected // faster than app.selection

                  if("TextRange" == _sel.typename){ // Text char selected: OK: verifed working

                      var _target = _sel;

                      result = "TextRange";

                  }else if(0 != _sel.length){ // Array: Single and Multiple items case

                      // $.writeln("Number of selection = ", _sel.length); // debug only

                      for(var i=0; i<_sel.length; i++){

                          if(i == 0){

                              result = _sel[i].typename;


                              if(result != _sel[i].typename){

                                  //$.writeln("Got Mixed"); // debug only

                                  result = "Mixed";





                  }else{ // No selection

                      // $.writeln("No selection == > Global mode"); // debug only

                      result = "NoSelection";



                  // no doc opened



              $.writeln("EXCEPTION: ", e);

              if(aiDebugAlertException) alert("EXCEPTION: " + e);


          $.writeln("aiGetSelectionType: result = ", result, " ", $.hiresTimer, " \xB5s"); // micro second

          return result;



      I'll appreciate any tips and suggestion.

      I made minimum code package to reproduce this issue.

      Please let me know for the test code package.


      Thank you,


        • 1. Re: [Q] CEP plugin response issue when Illustrator is in background. Any solution?
          Ten A Adobe Community Professional


          I don't have any solution about that. However, We can use another callback mechanism.

          Why don't you try to plugplugInterface like below?


          1. Remove your evalScripts 2nd argument(callback function).

          2. Add below event listener and new callback function.

          //Javascript (HTML)
          csi.addEventListener("getCallback", getReturnValue);
          function getReturnValue(response) { // bypass for performance
            console.timeEnd("pollAi"); // performance measurement (NodeJs)
            console.log('response = ' + response.data);
            // other business logic
            AiSupport.inPoll = false;


          3. Replace last line(return result;) of your aiGetSelectionType function to below code.

          var xLib = new ExternalObject("lib:\PlugPlugExternalObject");
          } catch (e) {
          var eventObj = new CSXSEvent(); 
          eventObj.type = "getCallback";
          eventObj.data = result; //result must be String
          if (app.activeDocument.selection.length>0){
            eventObj.data = app.activeDocument.selection[0].reflect.properties.length.toString();


          You can reference below project.

          https://github.com/ten-A/CreativeSuiteSDK_Experimentals/tree/master/net.sytes.chuwa.callba cktest

          1 person found this helpful
          • 2. Re: [Q] CEP plugin response issue when Illustrator is in background. Any solution?
            Naoki-Hada Level 1

            Ten A


            Thank you very much for the tips and code.

            I've tested with the PlugPlugExternalObject event handler.

            Code itself worked fine.


            But the response slowness still happening.


            Another trying was disabling App Nap on Illustrator as commented previous post.

            [Q] Illustrator seems forgeting what selected after 50 sec on Mac. How to avoid?


            > Following seems working from short term testing and did not show any slowness..


            >That is command to run in Terminal.

            >After done, Illustrator need to restart.


            >Turn off App Nap for Illustrator (not default setting)


            >defaults write com.adobe.illustrator NSAppSleepDisabled -bool true



            >Resume default: App Nap for Illustrator


            >defaults write com.adobe.illustrator NSAppSleepDisabled -bool false



            If there's other option other than above OS settings, it would be better.


            Thank you,