14 Replies Latest reply on Oct 9, 2009 2:04 PM by CTC Imaging

    [JS] (CS4) Issue with menuAction "Close"

    CTC Imaging

      Hello Kasyan, Olav or anyone else (for that fact)

       

      The menuAction "Close" EventListener may be bugged? You will get an error going through the second loop (Loaded Actions)!!! Any other eventListeners I tried (Open, Print, ...) work. It looks like once you add the eventListener for Close, it ends up w/ TWO events according to app.menuActions.item("Close").eventListeners.length.

      Any idea?
      Thank you, Alex.

      =========================== Code =================================
      #target indesign
      #targetengine "session"
      //app.scriptPreferences.version = 5.0;

       

      //*** Initialize LOCAL Variables
      var myScriptName = app.activeScript.fsName;
      var myScriptPath = app.activeScript.path;
      var myDept = "PrePress";

       

      //*** Initialize GLOBAL Variables

      app.scriptArgs.set("Event_Open", myScriptPath + "/"+myDept+"OPEN.jsx");
      app.scriptArgs.set("Event_Close", myScriptPath + "/"+myDept+"CLOSE.jsx");
      app.scriptArgs.set("Event_Copy", myScriptPath + "/"+myDept+"COPY.jsx");
      app.scriptArgs.set("Event_Clean", myScriptPath + "/"+myDept+"CLEAN.jsx");
      app.scriptArgs.set("Event_Print", myScriptPath + "/"+myDept+"PRINT.jsx");

       

      //******************** BEGIN Main ********************

      var tmp = "List of Actions removed\n------------------------\n";
      var myActions = app.menuActions.item("Open...").eventListeners;
      for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
      {

          tmp += "Action : "  + myActions[cpt].parent.name + "\t\tType: " + myActions[cpt].eventType + "\n";
          myActions[cpt].remove();
      }

      var myActions = app.menuActions.item("Close").eventListeners;
      for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
      {
          tmp += "Action : "  + myActions[cpt].parent.name + "\t\tType: " + myActions[cpt].eventType + "\n";
          myActions[cpt].remove();
      }

      //******************** ACTION  ********************
      app.menuActions.item("Open...").addEventListener("afterInvoke", ActionOpen, false);
      app.menuActions.item("Close").addEventListener("beforeInvoke", ActionClose, false);

      tmp += "\nList of Actions loaded\n-----------------------\n";
      var myActions = app.menuActions.item("Open...").eventListeners;
      for (var cpt = 0; cpt < myActions.length; cpt++)
          tmp += "Action : "  + myActions[cpt].parent.name + "\t\tType: " + myActions[cpt].eventType + "\n";

      var myActions = app.menuActions.item("Close").eventListeners;
      for (var cpt = 0; cpt < myActions.length; cpt++)
          tmp += "Action : "  + myActions[cpt].parent.name + "\t\tType: " + myActions[cpt].eventType + "\n";

       

      alert ("\tTEST Area\n\t=======\n\n"+tmp);

      //******************** END Main ********************

      //****************** FUNCTIONS Definitions ********************

      function ActionOpen (itsAction)
      {
      var myExeSrcFile = new File (app.scriptArgs.get("Event_Open"));
        if (myExeSrcFile.exists)
        {
        myExeSrcFile.open ('r:(read)');
        app.doScript(myExeSrcFile, ScriptLanguage.javascript);
        myExeSrcFile.close();
        }
        else
          alert ("Error! Missing File:\n\n" + myExeSrcFile.fsName);
        return;
      }

       

      function ActionClose (itsAction)
      {
      var myExeSrcFile = new File (app.scriptArgs.get("Event_Close"));
        if (myExeSrcFile.exists)
        {
        myExeSrcFile.open ('r:(read)');
        app.doScript(myExeSrcFile, ScriptLanguage.javascript);
        myExeSrcFile.close();
        }
        else
          alert ("Error! Missing File:\n\n" + myExeSrcFile.fsName);
        return;
      }

        • 1. Re: [JS] (CS4) Issue with menuAction "Close"
          Kasyan Servetsky Level 5

          Hi Alex,

           

          First of all, please describe what you want your script to do, and post the scripts that are triggered by it – CLOSE.jsx at least. As far as I understand, you want some scripts to be triggered when a user selects some commands in InDesign. But it seems to me that you overcomplicated things to much.

           

          What strike my eye at the beginning of your script is that the paths to jsx-files when you set script arguments are not correct: slash is missing.

          Then why do you read your jsx-files?

          myExeSrcFile.open ('r:(read)');

          You don’t need to do it.

           

          Here is, as an example, a script that I use:

           

          #targetengine "session"

          myScriptPath = app.filePath + "/Scripts/Scripts Panel/ExportEachPageAsJPEG and Save v6.2.jsx";

          var myFile = new File (myScriptPath);

          if (myFile.exists) {

                      var myEventListener = app.addEventListener( "afterSave", myFile, false );

          }

          else {

                      alert("This script is not installed: \"" + myFile.fsName + "\" -- call Kasyan, when he comes to work.");

          }

           

          Two events are indeed problematic in InDesign: afterOpen and beforeClose, but they were discussed before in this forum. And I can’t tell you anything without knowing what CLOSE.jsx does.

           

          Kasyan

          1 person found this helpful
          • 2. Re: [JS] (CS4) Issue with menuAction "Close"
            CTC Imaging Level 1

            Actually, this is a CS3 STARTUP script assigning the menuActions. Ready it back yesterday, I was wondering why I did not point directly to a file! Last year when I wrote these, I've picked up some code from others trying to achieve the same. This code works great in CS3 but the "Close" actions triggers an error in CS4. So the engine change somewhat within the eventListeners. Once at work, I will post the "PrePressCLOSE.jsx" file. In regard of the path being wrong, it is actually correct. The files have "PrePress" as a prefix for those specific menuActions files. Just a legacy from InEventScript pluggin we used in CS2.

            • 3. Re: [JS] (CS4) Issue with menuAction "Close"
              Kasyan Servetsky Level 5

              I thought that "PrePress" was the name of a folder.

              The trial period for my copy of InDesign CS4 has expired — so I can’t test your script with it (I’m currently on CS3).

               

              Kasyan

              • 4. Re: [JS] (CS4) Issue with menuAction "Close"
                CTC Imaging Level 1

                Here is a cleanup version. I followed your suggestion. Don't ask me why I did not apply a file to the handler!!! Much easier now, and I've used a function since I am repeating several time for different Actions. It works perfectly in CS3. But in CS4 the InfoEvent function reports "Object is invalid" when looping through the events of the "Close" menuAction. What I've observed:

                1) It looks like 2 entries are created eventhough only 1 Eventistener was added. alert (app.menuActions.item("Close").eventListeners.length); But they seem unaccessible!?!

                2) If you rerun the script afterwards, you'll get an error when the script tries to remove the eventListener for the "Close" menuAction.

                3) If you disable line code app.menuActions.item("Close").addEventListener(..., the script completes, after you HAVE restarted InDesign.

                4) Still an error when assigning a different file as the handler ie: var myFile = new File (app.scriptArgs.get("Event_Open"));

                5) Disable script version line code, same error.

                 

                I think point 1 is the area to investigate. Why are 2 created?

                 

                I am including at the end the CLOSE script, but I think it's irrelevant since it was model after the OPEN script. Which loads correctly.

                All scripts execute correctly in standalone (manualy triggered) mode.

                 

                Thank you for you help, Alex.

                 

                =================================== Code (STARTUP) ===============================

                 

                #target indesign
                #targetengine "session"
                app.scriptPreferences.version = 5.0;

                //******************** BEGIN Main ********************

                //*** Initialize LOCAL Variables
                var myScriptName = app.activeScript.fsName;
                var myScriptPath = app.activeScript.path;

                var myDept = "PrePress";
                var myStyle_Default = "Normal"     //*** Default Style
                var myStyleSet_Default = "Imprint"     //*** Default StyleSet
                var myStyleSet_Prefix = "Styles"     //*** Naming Convention
                var myStyleSet_Error = "*****Error while Updating!"
                var myStyleSet_Updt = "*****No UpDate! (Delete to Reset)";

                //*** Initialize GLOBAL Variables
                app.userName = GetUser().toUpperCase();
                app.pdfPlacePreferences.pageNumber = 1;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                SkipWRDS = new Array;

                //*** Initialize SCRIPT Variables
                app.scriptArgs.clear();
                app.scriptArgs.set("Department", myDept);
                app.scriptArgs.set("Style_Default", myStyle_Default);
                app.scriptArgs.set("StyleSet_Default", myStyleSet_Default);
                app.scriptArgs.set("StyleSet_Prefix", myStyleSet_Prefix);
                app.scriptArgs.set("StyleSet_Error", myStyleSet_Error);
                app.scriptArgs.set("StyleSet_Msg", myStyleSet_Updt);
                app.scriptArgs.set("Event_Path", myScriptPath);     //***Path to InEventScript Plug-In
                app.scriptArgs.set("Event_Open", myScriptPath + "/"+myDept+"OPEN.jsx");
                app.scriptArgs.set("Event_Close", myScriptPath + "/"+myDept+"CLOSE.jsx");
                app.scriptArgs.set("Event_Copy", myScriptPath + "/"+myDept+"COPY.jsx");
                app.scriptArgs.set("Event_Clean", myScriptPath + "/"+myDept+"CLEAN.jsx");
                app.scriptArgs.set("Event_Print", myScriptPath + "/"+myDept+"PRINT.jsx");
                app.scriptArgs.set("Event_App", myScriptPath + "/"+myDept+"APPPreferences.jsx");
                app.scriptArgs.set("Event_Doc", myScriptPath + "/"+myDept+"DOCPreferences.jsx");
                //app.scriptArgs.set("Event_Test", myScriptPath + "/"+myDept+"TEST.jsx");     //***Debug MODULE

                //*** REMOVE all EVENTS
                app.eventListeners.everyItem().remove();

                //*** REMOVE all ACTIONS
                var myActions = app.menuActions.item("Open...").eventListeners;
                for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                myActions[cpt].remove();
                var myActions = app.menuActions.item("Close").eventListeners;
                for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                myActions[cpt].remove();
                var myActions = app.menuActions.item("Copy").eventListeners;
                for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                myActions[cpt].remove();
                var myActions = app.menuActions.item("Paste").eventListeners;
                for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                myActions[cpt].remove();
                var myActions = app.menuActions.item("Print...").eventListeners;
                for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                myActions[cpt].remove();

                //******************** APPLICATION Preferences ********************
                var myFile = new File(app.scriptArgs.get("Event_App"));
                if (FileExist (myFile))
                {
                myFile.open ('r:(read)');
                app.doScript(myFile, ScriptLanguage.javascript);
                myFile.close();
                }

                //*** Check ERROR Updating.
                var myStyleStatus = app.paragraphStyles.item(myStyleSet_Error);
                try
                {
                  myStyleStatus.name;     //*** ERROR if Style does NOT Exists.
                  alert ("There was an ERROR while Updating Styles PREVIOUSLY!\n\nPlease make sure PrePressStylesXXX exist here!\n\n" + myScriptPath);
                  myStyleStatus.remove();
                }
                catch (e)
                {
                }

                var myArea = myScriptPath.slice(myScriptPath.lastIndexOf("/")+1).toUpperCase();
                myArea = myArea.replace("%20", " ");
                var tmp = (app.userName + ":" + myArea + " Area\n=======\n\n");

                //*** IMPORTING Application Styles
                ResetStyles (app.paragraphStyles, "", /\*\*\*/, "");     //*** Updates  & Messages Starts with "***"
                tmp += "\nList of ParagraphStyles loaded\n--------------------------------\n";
                //alert ("Importing Styles...");
                var myFound = false;
                var myStyleFiles = Folder(myScriptPath).getFiles(myDept+myStyleSet_Prefix+"*.indt");
                for (var cpt = 0; cpt < myStyleFiles.length; cpt++)
                {
                  try
                  {
                    app.pdfPlacePreferences.pageNumber = 99999;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                    app.importStyles(ImportFormat.paragraphStylesFormat, myStyleFiles[cpt], GlobalClashResolutionStrategy.loadAllWithOverwrite);
                  app.scriptArgs.set("StyleSet-"+cpt, myStyleFiles[cpt].name);
                  tmp += myStyleFiles[cpt].name + "\n";
                  var myExp = new RegExp(myStyleSet_Default, "i")
                  myFound = myFound || ((myExp.test(myStyleFiles[cpt].name)) &&
                                     (GetStyle (app.paragraphStyles, "\\*\\*\\*"+myStyleSet_Default, "") != -1));
                  try
                  {
                   app.paragraphStyles.item(myStyle_Default).remove();
                  }
                  catch (e)
                  {
                   alert ("The TEMPLATE [***"+myStyleFiles[cpt].name+"] is MISSING style: "+myStyle_Default+"!!!\n\nScript ABORTED...");
                   exit();
                  }
                  }
                  catch (e)
                  {
                  try
                  {
                   app.paragraphStyles.add({name: myStyleSet_Error});
                  }
                  catch (e)
                  {
                  }
                  alert ("No Template to CREATE the Application StyleSet with!!!\n\nPlease create this FILE in that FOLDER:\n"+myStyleFiles[cpt].fsName);
                  }
                app.pdfPlacePreferences.pageNumber = 1;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                //alert ("Loading StyleSet:\n"+myStyleFiles[cpt].fsName);
                }

                if (myFound == false)     ///*** Default StyleSet NOT found
                {
                alert ("The System MUST have:"+
                      "\n1) an APPLICATION StyleSet named: [***"+myStyleSet_Default+" ...]"+
                      "\n2) in a TEMPLATE named: ["+myDept+myStyleSet_Prefix+'"'+myStyleSet_Default+".indt]"+
                      "\n3) with at least this STYLE named: "+myStyle_Default+"\n\nScript ABORTED...");
                exit();
                }

                ResetStyles (app.paragraphStyles, "", "", /\*\*\*/);     //*** Updates  & Messages Starts with "***"

                //alert ("Styles Reset...");

                //******************** EVENTS  ********************
                //app.addEventListener("afterOpen", EventOpen, false);     //STILL INDESIGN CRASH with OPEN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

                tmp += "\nList of Events loaded\n----------------------\n";
                tmp += EventInfo (app.eventListeners);

                //******************** END Main ********************

                //******************** ACTIONS  ********************
                var myFile = new File (app.scriptArgs.get("Event_Open"));
                if (FileExist (myFile))
                app.menuActions.item("Open...").addEventListener("afterInvoke", myFile, false);
                var myFile = new File (app.scriptArgs.get("Event_Close"));
                if (FileExist (myFile))
                app.menuActions.item("Close").addEventListener("beforeInvoke", myFile, false);
                var myFile = new File (app.scriptArgs.get("Event_Copy"));
                if (FileExist (myFile))
                app.menuActions.item("Copy").addEventListener("afterInvoke", myFile, false);
                var myFile = new File (app.scriptArgs.get("Event_Clean"));
                if (FileExist (myFile))
                app.menuActions.item("Paste").addEventListener("afterInvoke", myFile, false);
                var myFile = new File (app.scriptArgs.get("Event_Print"));
                if (FileExist (myFile))
                app.menuActions.item("Print...").addEventListener("beforeInvoke", myFile, false);

                tmp += "\nList of Actions loaded\n-----------------------\n";
                tmp += EventInfo (app.menuActions.item("Open...").eventListeners);
                tmp += EventInfo (app.menuActions.item("Close").eventListeners);
                tmp += EventInfo (app.menuActions.item("Copy").eventListeners);
                tmp += EventInfo (app.menuActions.item("Paste").eventListeners);
                tmp += EventInfo (app.menuActions.item("Print...").eventListeners);

                alert (tmp);

                //****************** FUNCTIONS Definitions ********************

                //*** Find 1st occurence of a Style name
                //Parameters:
                //itsStyles: Object/Paragraph/Character Style. {Object}
                //itsMaskInclude: Pattern which to INCLUDES (Expression). EMPTY string will be ALL
                //itsMaskExclude: Pattern which to EXCLUDES (Expression). EMPTY string will be N.A.
                //Return: Pointer to Style or -1 if not found.
                function GetStyle (itsStyles, itsMaskInc, itsMaskExc)
                {
                  if (itsMaskExc == "")
                    itsMaskExc = "N.A.";
                  for (var cpt = 0; cpt < itsStyles.length; cpt++)
                  {
                    var myInc = new RegExp(itsMaskInc);
                    var myExc = new RegExp(itsMaskExc);
                    if (myInc.test(itsStyles[cpt].name) && !myExc.test(itsStyles[cpt].name))
                      return (itsStyles[cpt]);
                  }
                  return -1;    //*** If it comes out of the loop it did NOT find
                }

                //*** Reset Styles and Save Formatting!!!!
                //Parameters:
                //itsStyles: Styles. {Object}
                //itsReplacement: Replacing Style. {String}
                //itsMaskInc: Check if Style Name is part of the INCLUSION. {Expression}
                //itsMaskExc: Check if Style Name is part of the EXCLUSION. {Expression}
                //Return: None.
                //Note: Loops BACKWARD to prevent loosing Formatting by DELETING a style WHICH is used as a "Next Style" in a FOLLOWING Style.
                //      Since the "Next Styles" are all defined before the PARENT Style, we need to dele the PARENT before the Child.
                function ResetStyles (itsStyles, itsReplacement, itsMaskInc, itsMaskExc)
                {
                if (itsMaskExc == "")
                  itsMaskExc = "N.A.";
                  if (itsReplacement == "")
                    itsReplacement = itsStyles[0];
                  try
                  {
                    itsReplacement.name;
                  }
                  catch (e)
                  {
                    itsReplacement = itsStyles[0];
                  }
                  for (var cpt = itsStyles.length-1; cpt >= 0; cpt--)
                  {
                    var myInc = new RegExp(itsMaskInc);
                  var myExc = new RegExp(itsMaskExc);
                    if ((itsStyles[cpt].name.search(myInc) > -1) &&  (itsStyles[cpt].name.search(myExc) == -1))
                  {
                   try
                   {
                    itsStyles[cpt].remove(itsReplacement);
                   }
                   catch (e)
                   {
                   }
                  }
                }
                }

                //*** List Info EventListeners
                //Parameters:
                //itsEvents: EventListeners to get info on. {Array Object}
                //Return: Info. {String}
                function EventInfo (itsEvents)
                {
                var tmp = "";
                for (var cpt = 0; cpt < itsEvents.length; cpt++)
                  tmp += "Event : "  + itsEvents[cpt].parent.name + "\tType: " + itsEvents[cpt].eventType + "\t          File: " + itsEvents[cpt].handler.name + "\n";
                return (tmp);
                }

                //*** USER Window's Account Name
                //Parameters:
                //Return itsUser {String}
                function GetUser()

                var itsUser = ($.os.substring(0, 7)=="Windows") 
                  ? $.getenv("USERNAME") 
                  : $.getenv("USER"); 
                return itsUser;
                }

                //*** Check if File Exists
                //Parameters:
                //itsFile: File to check. {Object}
                //Return: result of its existance.
                function FileExist (itsFile)
                {
                if (itsFile.exists)
                  return true;
                else
                  alert ("Error! Missing File:\n\n" + itsFile.fsName);
                return false;
                }

                ========================== code (CLOSE) =========================

                #target indesign
                #include "PrePressLIBRARY.jsxinc"
                app.scriptPreferences.version = 5.0;

                //******************** BEGIN Main ********************

                if (app.modalState)     //*** Alert already displayed
                  exit();

                if (app.pdfPlacePreferences.pageNumber == 99999)
                {
                  app.pdfPlacePreferences.pageNumber = 1;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                  exit();
                }

                var myScriptName = app.activeScript.fsName;
                var myScriptPath = app.activeScript.path;
                var myPrefExe = app.scriptArgs.get("Event_Doc");
                var myCleanExe = app.scriptArgs.get("Event_Clean");
                var myStyleSet_Error = app.scriptArgs.get("StyleSet_Error");
                var myStyleSet_Updt = app.scriptArgs.get("StyleSet_Updt");
                var myStyle_Default = app.scriptArgs.get("Style_Default");

                if (app.documents.length == 0)
                  exit();

                var myDoc = app.activeDocument;

                if (app.scriptPreferences.version[0] >= "5")
                myDoc.layoutWindows[0].screenMode = ScreenModeOptions.PREVIEW_OFF;     //*** 1936552047
                myDoc.layoutWindows[0].proofingType = ProofingType.PROOF_OFF;     //*** 1347710822
                //myDoc.layoutWindows[0].overprintPreview = false;

                if (!isNaN(myDoc.name.substring(1,8)))
                {
                try
                {
                  var myDocFile = new File (myDoc.fullName+"");
                }
                catch (e)
                {
                  alert  ("This Document was CONVERTED from Previous Version!!!\n\nDo NOT Save ... [" + myDoc.name + "]");
                  exit();
                }
                }
                else
                exit ();

                //*** Check UPDATE Status.
                try    
                {
                  myDoc.paragraphStyles.item(myStyleSet_Updt).name;
                //  alert ("["+myDoc.name+"] is set to: "+myStyleSet_Updt+"\n\nScript ABORTED...");
                  exit();
                }
                catch (e)
                {
                }

                //*** Check ERROR Status.
                try
                {
                  myDoc.paragraphStyles.item(myStyleSet_Error).name;
                  alert ("There was an ERROR while Updating Styles PREVIOUSLY!");
                }
                catch (e)
                {
                }

                var myCHKS = new Array;
                var myPasteBox = LocatePasteBox (myDoc);     //*** Pastebox NOT found returns -1
                  
                if (myDoc.modified)
                {
                myDoc.metadataPreferences.description += app.userName+" ("+Date().slice(0,-12)+")\n";
                if (myPasteBox == -1)     //*** NOT Found
                {
                  var myTFS = myDoc.layoutWindows[0].activeLayer.textFrames;
                  for (var cptTF = 0; cptTF < myTFS.length; cptTF++)     //*** Look for IMPRINT TextFrame
                  {
                   if (myTFS[cptTF].label.toUpperCase() == "IMPRINT")
                   {
                         var myPasteBox = myTFS[cptTF].parentStory;
                    myCHKS.push(myTFS[cptTF]);
                    break;
                   }
                  }
                  if ((app.selection.length == 1) && (cptTF == myTFS.length))     //*** NOT Found
                   var myPasteBox = app.selection[0].parentStory;
                  if (myCHKS.length == 0)
                   for (var cptSEL = 0; cptSEL < app.selection.length; cptSEL++)
                    myCHKS.push(app.selection[cptSEL]);     //** NO PasteBox.,use the SELECTION(s)
                }
                else
                  myCHKS.push(myPasteBox);

                  CheckAbbreviation (myCHKS);     //*** Check ONLY Pastebox if AVAILABLE

                }
                else
                {

                //*** Get STYLESET.
                var myStyleSet = GetStyleSet(myDoc, myDoc.paragraphStyles);

                //***Check STYLESET Status.
                try
                {
                  app.paragraphStyles.item(myStyleSet[0]).name;     //*** Style are UP-TO-DATE
                //  alert ("["+myDoc.name+"] Styles are UpToDate!");
                }
                catch (e)
                {
                //*** 5 DAYS to be a PREVIOUS Order
                //*** Calcute Time Elapsed since File Creation. OLD would be at least 1 hour.
                  var myDate = new Date();
                  try
                  {
                   var myDocFile = new File (myDoc.fullName+"");
                  }
                  catch (e)
                  {
                   exit();
                  }
                  if (Math.floor((myDate.getTime() - myDocFile.created.getTime())/1000) > 10 * 24 * 3600)
                   exit();
                  else
                  {
                    alert ("Styles are NOT up-to-date!\n\nPlease run OPEN script...");
                //   ExecuteScript (app.scriptArgs.get("Event_Open"));
                  }
                }
                }

                switch (true)     //*** Different Imprint type, different FINAL Behaviour
                {
                //*** Copy to a Batch Printing Folder on Desktop
                  case (myDoc.name.search(/(KSG)|(KPC\d{2})|(KGC[CF]?\d{2}[^F])|(GEV634)|(GEVF)|(GLHF)|(ATY[^E]) |(APE)|(RLE)|(RE208A)/i) > -1):
                  if ((myPasteBox != -1) && (myPasteBox.contents != ""))     //*** PasteBox Found
                  {
                   app.select(myPasteBox.texts[0]);     //*** Select ALL text INCLUDING overset   
                   app.copy();
                  }
                    var myDate = new Date();
                  var myUserName = GetUser().toUpperCase();
                //    var myFolder = new Folder("~/Desktop/BATCH-" + myDate.toDateString().slice(4));
                  var myFolder = new Folder(myScriptPath+"/../~BATCH/"+myUserName+"/"+myDate.toDateString().slice(4));
                  var myDocFile = new File(myDoc.fullName+"");
                  var myFiles = GetAllFiles (myFolder, [], myDocFile.name, "", false);
                  if (myFiles.length == 0)     //** NOT Found
                  {
                   var myFiles = GetAllFiles (myFolder, [], "", "", false);
                   if (myFiles.length == 0)
                     myPOS = 0;
                   else
                    var myPOS = eval(myFiles[myFiles.length-1].name.slice(0,2)) + 1;     //*** Last File Entry's Number + 1
                   var myTargetFile = new File(myFolder.fsName+"/"+("00"+myPOS).slice(-2)+"-"+myDocFile.name);
                  }
                  else
                    var myTargetFile = new File(myFiles[0]);
                    var myAnswer = confirm ("Include this file in the BATCH Printing? (Y/N)");
                  if (myAnswer == true)
                  {
                   try
                   {
                    myDoc.save();
                   }
                   catch (e)
                   {
                    alert ("Could not SAVE the document!!! Script ABORTED...");
                    exit();
                   }
                   if (!myFolder.exists)
                    myFolder.create();
                   if (myTargetFile.exists)     //*** Copy and False RETURNED if error
                    if (myDocFile.copy(myTargetFile))     //*** Copy and False RETURNED if error
                     alert ("RE-Copied [ "+myTargetFile.name+" ]\n\n to BATCH Folder: "+myUserName+"/"+myDate.toDateString().slice(4));
                    else
                     alert ("Error copying\n\n"+myTargetFile.fsName);
                   else
                    if (myDocFile.copy(myTargetFile))     //*** Copy and False RETURNED if error
                     alert ("COPIED [ "+myTargetFile.name+" ]\n\n to BATCH Folder: "+myUserName+"/"+myDate.toDateString().slice(4));
                    else
                     alert ("Error copying\n\n"+myTargetFile.fsName);
                  }
                  else
                  {
                   if (myFolder.exists)
                   {
                    var myFiles = GetAllFiles (myFolder, [], myDocFile.name, "", false);
                    var myTargetFile = new File(myFiles[0]);
                    if (myTargetFile.remove())
                     alert ("REMOVED [ "+myTargetFile.name+" ]\n\n from BATCH Folder: "+myUserName+"/"+myDate.toDateString().slice(4));
                   }
                  }
                break;
                //*** BATCH Imprint Copy PasteBox content or Currently Selected Box
                  case (myDoc.modified):

                //*** Get STYLESET.
                  var myStyleSet = GetStyleSet(myDoc.name, myDoc.paragraphStyles);
                //***Check STYLESET Status.
                  try
                  {
                   app.paragraphStyles.item(myStyleSet[0]).name;
                     
                      FitLayout (myDoc);
                       
                      if (myPasteBox == -1)     //*** PasteBox NOT Found
                    if (app.selection.length == 1)
                          var myPasteBox = app.selection[0].parentStory;
                    else
                          break;
                   if (myPasteBox.contents != "")
                   {   
                    while (myPasteBox.overflows)
                     myPasteBox.geometricBounds = [myPasteBox.geometricBounds[0],
                                              myPasteBox.geometricBounds[1],
                                              myPasteBox.geometricBounds[2] + 1,
                                              myPasteBox.geometricBounds[3]];
                           
                    if (myDoc.name.search(/RE208[BC]/i) > -1)
                     app.select(myPasteBox);     //*** Select the TextFrame
                    else
                     app.select(myPasteBox.texts[0]);     //*** Select ALL text INCLUDING overset
                    
                    app.copy();
                     if (!isStyled (myPasteBox))     //*** Check Pastebox
                     alert ("The PasteBox is NOT COMPLETELY Formatted with STYLES!!!");
                   }
                  }
                  catch (e)
                  {
                   alert ("The Styles are NOT Up-to-date!!!\n\nDocument should NOT be Saved...");
                  }
                break;
                default:
                  break;
                }

                //******************** END Main ********************

                //****************** FUNCTIONS Definitions ********************

                • 5. Re: [JS] (CS4) Issue with menuAction "Close"
                  Kasyan Servetsky Level 5

                  Alex,

                   

                  I can’t start my copy of CS4 any more – demo period is over. So I can’t check your script .

                   

                  Kasyan

                  • 6. Re: [JS] (CS4) Issue with menuAction "Close"
                    CTC Imaging Level 1

                    Hello Kasyan,

                     

                    I was wondering if you have CS4 now. I just had it installed yesterday, not a trial, and I am ready to resume debugging my CS3 script.

                     

                    Looks like I still have issue with ACTION eventlisteners. I am getting invalid Objects when I try to list them. Works great in CS3.

                     

                    ALL scripts have "app.scriptPreferences.version = 5.0;" at the beginning to refer to the correct engine.

                     

                    The actions get loaded at Startup, by placing EVENTS.jsx and STARTUP.jsx  in the Startup Script folder.

                     

                    I have attached both scripts. As well as a setup file, that may help you simulate on your end.

                     

                    FYI: I have a file inclusion: #include "PrePressLIBRARY.jsxinc" where a bunch of functions are defined. I dissabled it in STARTUP to keep it clean.

                    Could that cause engine reference issues, in other scripts I trigger through actions and/or the Script UI panel?

                     

                    Contact me, if you need more files...

                     

                    Thanks, Alex.

                    • 7. Re: [JS] (CS4) Issue with menuAction "Close"
                      CTC Imaging Level 1

                      Kasyan,

                       

                      I don't know if your received the attachement? I received an error when I tried.

                       

                      I am attaching them again.

                      • 8. Re: [JS] (CS4) Issue with menuAction "Close"
                        Kasyan Servetsky Level 5

                        Hi Alex,

                         

                        I was wondering if you have CS4 now.

                        I have access to a copy of ID CS4, but it is installed on my college's machine, not mine, so this is a little problem for me.

                        I have attached both scripts. As well as a setup file, that may help you simulate on your end.

                         

                        I don't see any files attached.

                         

                        Kasyan

                        • 9. Re: [JS] (CS4) Issue with menuAction "Close"
                          CTC Imaging Level 1

                          Atttachments are obviously blocked.

                           

                          EVENTS.jsx

                          ===================

                          #target indesign
                          #targetengine "session"
                          app.scriptPreferences.version = 5.0;

                          //******** IMPORTANT ********
                          //******** NO alert in this script so it executes silently  ********

                          //******************** BEGIN Main ********************

                          var myScriptPath = app.activeScript.path;

                          app.scriptArgs.set("Event_Open", myScriptPath+"/OPEN.jsx");
                          app.scriptArgs.set("Event_Close", myScriptPath+"/CLOSE.jsx");
                          app.scriptArgs.set("Event_Save", myScriptPath+"/SAVE.jsx");
                          app.scriptArgs.set("Event_Copy", myScriptPath+"/COPY.jsx");
                          app.scriptArgs.set("Event_Clean", myScriptPath+"/CLEAN.jsx");
                          app.scriptArgs.set("Event_Print", myScriptPath+"/PRINT.jsx");
                          app.scriptArgs.set("Event_Test", myScriptPath+"/TEST.jsx");     //***Debug MODULE

                          //*** REMOVE all EVENTS
                          app.eventListeners.everyItem().remove();

                          //*** REMOVE all ACTIONS
                          var myActions = app.menuActions.item("Open...").eventListeners;
                          for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                          myActions[cpt].remove();
                          var myActions = app.menuActions.item("Close").eventListeners;
                          for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                          myActions[cpt].remove();
                          var myActions = app.menuActions.item("Save").eventListeners;
                          for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                          myActions[cpt].remove();
                          var myActions = app.menuActions.item("Copy").eventListeners;
                          for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                          myActions[cpt].remove();
                          var myActions = app.menuActions.item("Paste").eventListeners;
                          for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                          myActions[cpt].remove();
                          var myActions = app.menuActions.item("Print...").eventListeners;
                          for (var cpt = myActions.length-1 ; cpt >= 0 ; cpt--)
                          myActions[cpt].remove();

                          //******************** EVENTS  ********************
                          //STILL INDESIGN CRASH with OPEN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                          /*
                          var myFile = new File (app.scriptArgs.get("Event_Open"));
                          if (FileExist (myFile))
                          {
                          app.addEventListener("afterOpen", EventOpen, false);
                          app.addEventListener("afterOpen", myFile, false);
                          }
                          */

                          //******************** ACTIONS  ********************
                          var myFile = new File (app.scriptArgs.get("Event_Close"));
                          if (FileExist (myFile))
                          app.menuActions.item("Close").addEventListener("beforeInvoke", myFile, false);
                          var myFile = new File (app.scriptArgs.get("Event_Save"));
                          if (FileExist (myFile))
                          app.menuActions.item("Save").addEventListener("beforeInvoke", myFile, false);
                          /* DISABLED. Not needed any longer.
                          var myFile = new File (app.scriptArgs.get("Event_Copy"));
                          if (FileExist (myFile))
                          app.menuActions.item("Copy").addEventListener("afterInvoke", myFile, false);
                          */
                          var myFile = new File (app.scriptArgs.get("Event_Clean"));
                          if (FileExist (myFile))
                          app.menuActions.item("Paste").addEventListener("afterInvoke", myFile, false);
                          var myFile = new File (app.scriptArgs.get("Event_Print"));
                          if (FileExist (myFile))
                          app.menuActions.item("Print...").addEventListener("beforeInvoke", myFile, false);
                          var myFile = null;

                          //******************** END Main ********************

                          //****************** FUNCTIONS Definitions ********************

                          /*
                          function EventOpen (itsEvent) ============= VERSION 1
                          {
                          if (app.pdfPlacePreferences.pageNumber == 99999)
                            app.pdfPlacePreferences.pageNumber = 1;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                          else
                          {
                            app.pdfPlacePreferences.pageNumber = 1;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                          //   itsEvent.preventDefault();
                          //   itsEvent.stopPropagation();
                            itsEvent.parent.windows.add();     //*** Doc. has no Window!!!
                          }
                          return;
                          }
                          */
                          /*
                          function EventOpen (itsEvent) ============= VERSION 2
                          {
                          var myFile = new File (app.scriptArgs.get("Event_Open"));
                          if (app.pdfPlacePreferences.pageNumber == 99999)
                            app.pdfPlacePreferences.pageNumber = 1;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                          else
                          {
                            app.pdfPlacePreferences.pageNumber = 1;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                          //   itsEvent.preventDefault();
                          //   itsEvent.stopPropagation();
                            itsEvent.parent.windows.add();     //*** Doc. has no Window!!!
                            myFile.open ('r:(read)');
                            app.doScript(myExeSrcFile, ScriptLanguage.javascript);
                            myFile.close();
                            }
                            return;
                          }
                          */

                          //*** Check if File Exists
                          //Parameters:
                          //itsFile: File to check. {Object}
                          //Return: result of its existance.
                          function FileExist (itsFile)
                          {
                          if (itsFile.exists)
                            return true;
                          else
                            alert ("Error! Missing File:\n\n" + itsFile.fsName);
                          return false;
                          }
                          ===================

                           

                          STARTUP.jsx

                          ===================

                          #target indesign
                          //#include "PrePressLIBRARY.jsxinc"
                          app.scriptPreferences.version = 5.0;

                          //******************** BEGIN Main ********************

                          //*** Initialize LOCAL Variables
                          var myScriptPath = app.activeScript.path;

                          var myProductionPath = "U:/ProductionOutput";
                          var myStockItemPath = "U:/StockItemTemplates";
                          var mySortQueuePath = "U:/FileStagingArea/SortQueue";
                          var myBatchPath = myProductionPath + "/~Batch";
                          var myFujiPath = myProductionPath + "/FujiPI2800/Finished/Imprints";
                          var myXantePath = myProductionPath + "/XantePlateMaker4/Finished";
                          var myTemplatePath = myProductionPath + "/Templates PREPRESS";

                          var myStyle_Default = "Normal"     //*** Default Style
                          var myStyleSet_Default = "Imprint"     //*** Default StyleSet
                          var myStyleSet_Prefix = "Styles"     //*** Naming Convention
                          var myStyleSet_Error = "*****Error while Updating!"
                          var myStyleSet_Updt = "*****No UpDate! (Delete to Reset)";

                          //*** Initialize GLOBAL Variables
                          app.userName = GetUser().toUpperCase();
                          app.pdfPlacePreferences.pageNumber = 1;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                          SkipWRDS = new Array;     //*** Database if words skipped per DOCUMENT.
                          var tmp = ("User Name: " + app.userName + "\n------------\n");

                          //*** Initialize SCRIPT Variables
                          //app.scriptArgs.clear();
                          app.scriptArgs.set("Style_Default", myStyle_Default);
                          app.scriptArgs.set("StyleSet_Default", myStyleSet_Default);
                          app.scriptArgs.set("StyleSet_Prefix", myStyleSet_Prefix);
                          app.scriptArgs.set("StyleSet_Error", myStyleSet_Error);
                          app.scriptArgs.set("StyleSet_Msg", myStyleSet_Updt);

                          app.scriptArgs.set("Script_Path", myScriptPath);
                          app.scriptArgs.set("Production_Path", myProductionPath);
                          app.scriptArgs.set("StockItem_Path", myStockItemPath);
                          app.scriptArgs.set("SortQueue_Path", mySortQueuePath);
                          app.scriptArgs.set("Batch_Path", myBatchPath);
                          app.scriptArgs.set("Fuji_Path", myFujiPath);
                          app.scriptArgs.set("Xante_Path", myXantePath);
                          app.scriptArgs.set("Template_Path", myTemplatePath);

                          app.scriptArgs.set("Event_Startup", myScriptPath+"/STARTUP.jsx");
                          app.scriptArgs.set("Event_App", myScriptPath+"/APPPreferences.jsx");
                          app.scriptArgs.set("Event_Doc", myScriptPath+"/DOCPreferences.jsx");
                          app.scriptArgs.set("Event_Events", myScriptPath+"/EVENTS.jsx");

                          var myLocation = myScriptPath.slice(myScriptPath.lastIndexOf("/")+1);
                          myLocation = myLocation.replace("%20", " ");
                          tmp += ("\nDomain: " + myLocation + "\n---------\n");

                          tmp += ("\nApplication Paths:\n-------------------\n");
                          tmp += "Production: " + myProductionPath + "\n";
                          tmp += "StockItems: " + myStockItemPath + "\n";
                          tmp += "Sort Queue: " + mySortQueuePath + "\n";
                          tmp += ("\nProduction Paths:\n-------------------\n");
                          tmp += "Batch: " + myBatchPath + "\n";
                          tmp += "Templates: " + myTemplatePath + "\n";
                          tmp += "Fuji: " + myFujiPath + "\n";
                          tmp += "Xante: " + myXantePath + "\n";

                          //******************** Application PREFERENCES ********************
                          ExecuteScript (app.scriptArgs.get("Event_App"));
                          //alert (app.scriptArgs.get("Event_App"));

                          //*** Check ERROR Updating.
                          var myStyleStatus = app.paragraphStyles.item(myStyleSet_Error);
                          try
                          {
                            myStyleStatus.name;     //*** ERROR if Style does NOT Exists.
                            alert ("There was an ERROR while Updating Styles PREVIOUSLY!\n\nPlease make sure PrePressStylesXXX exist here!\n\n" + myScriptPath);
                            myStyleStatus.remove();
                          }
                          catch (e)
                          {
                          }

                          //*** IMPORTING Application Styles
                          ResetStyles (app.paragraphStyles, "", /\*\*\*/, "");     //*** Updates  & Messages Starts with "***"
                          tmp += "\nParagraphStyles loaded\n-------------------------\n";
                          //alert ("Importing Styles...");
                          var myFound = false;
                          var myStyleFiles = Folder(myScriptPath).getFiles(myStyleSet_Prefix+"*.indt");
                          for (var cpt = 0; cpt < myStyleFiles.length; cpt++)
                          {
                            try
                            {
                              app.pdfPlacePreferences.pageNumber = 99999;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                              app.importStyles(ImportFormat.paragraphStylesFormat, myStyleFiles[cpt], GlobalClashResolutionStrategy.loadAllWithOverwrite);
                            app.scriptArgs.set("StyleSet-"+cpt, myStyleFiles[cpt].name);
                            tmp += myStyleFiles[cpt].name + "\n";
                            var myExp = new RegExp(myStyleSet_Default, "i")
                            myFound = myFound || ((myExp.test(myStyleFiles[cpt].name)) &&
                                               (GetStyle (app.paragraphStyles, "\\*\\*\\*"+myStyleSet_Default, "") != -1));
                            try
                            {
                             app.paragraphStyles.item(myStyle_Default).remove();
                            }
                            catch (e)
                            {
                             alert ("The TEMPLATE [***"+myStyleFiles[cpt].name+"] is MISSING style: "+myStyle_Default+"!!!\n\nScript ABORTED...");
                             exit();
                            }
                            }
                            catch (e)
                            {
                            try
                            {
                             app.paragraphStyles.add({name: myStyleSet_Error});
                            }
                            catch (e)
                            {
                            }
                            alert ("No Template to CREATE the Application StyleSet with!!!\n\nPlease create this FILE in that FOLDER:\n"+myStyleFiles[cpt].fsName);
                            }
                          app.pdfPlacePreferences.pageNumber = 1;     //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
                          //alert ("Loading StyleSet:\n"+myStyleFiles[cpt].fsName);
                          }

                          if (!myFound)     ///*** Default StyleSet NOT found
                          {
                          alert ("The System MUST have:"+
                                "\n1) an APPLICATION StyleSet named: [***"+myStyleSet_Default+" ...]"+
                                "\n2) in a TEMPLATE named: ["+myStyleSet_Prefix+'"'+myStyleSet_Default+".indt]"+
                                "\n3) with at least this STYLE named: "+myStyle_Default+"\n\nScript ABORTED...");
                          exit();
                          }

                          ResetStyles (app.paragraphStyles, "", "", /\*\*\*/);     //*** Updates  & Messages Starts with "***"

                          //alert ("Styles Reset...");

                          //******************** EVENTS  ********************
                          tmp += "\nEvents loaded\n---------------\n";
                          tmp += EventInfo (app.eventListeners);

                          //******************** ACTIONS  ********************
                          tmp += "\nActions loaded\n----------------\n";
                          tmp += EventInfo (app.menuActions.item("Open...").eventListeners);
                          tmp += EventInfo (app.menuActions.item("Close").eventListeners);
                          tmp += EventInfo (app.menuActions.item("Save").eventListeners);
                          tmp += EventInfo (app.menuActions.item("Copy").eventListeners);
                          tmp += EventInfo (app.menuActions.item("Paste").eventListeners);
                          tmp += EventInfo (app.menuActions.item("Print...").eventListeners);

                          alert (tmp);

                          //******************** END Main ********************

                          //****************** FUNCTIONS Definitions ********************

                          //*** List Info EventListeners
                          //Parameters:
                          //itsEvents: EventListeners to get info on. {Array Object}
                          //Return: Info. {String}
                          function EventInfo (itsEvents)
                          {
                          var tmp = "";
                          for (var cpt = 0; cpt < itsEvents.length; cpt++)
                            tmp += "Event : "  + itsEvents[cpt].parent.name + "\tType: " + itsEvents[cpt].eventType + "\t          File: " + itsEvents[cpt].handler.name + "\n";
                          return (tmp);
                          }

                          //*** EXECUTES an External Script
                          //Parameters:
                          //itsPasteSource: FileName of the Source. {String}
                          //Return: Nothing.
                          function ExecuteScript (itsExeSource)
                          {
                            try
                            {
                              var myExeSrcFile = new File(itsExeSource);
                              myExeSrcFile.open ('r:(read)');
                              app.doScript(myExeSrcFile, ScriptLanguage.javascript);
                              myExeSrcFile.close();
                            }
                            catch (e)
                            {
                              alert ("Execution Error in this file: \n\n"+myExeSrcFile.fsName);
                            }
                            return;
                          }

                          //*** Reset Styles and Save Formatting!!!!
                          //Parameters:
                          //itsStyles: Styles. {Object}
                          //itsReplacement: Replacing Style. {String}
                          //itsMaskInc: Pattern which to INCLUDES (Expression). EMPTY string will be ALL. {RegExp}
                          //itsMaskExc: Pattern which to EXCLUDES (Expression). EMPTY string will be N.A. {RegExp}
                          //Return: None.
                          //Note: Loops BACKWARD to prevent loosing Formatting by DELETING a style WHICH is used as a "Next Style" in a FOLLOWING Style.
                          //      Since the "Next Styles" are all defined before the PARENT Style, we need to dele the PARENT before the Child.
                          function ResetStyles (itsStyles, itsReplacement, itsMaskInc, itsMaskExc)
                          {
                          //alert ("Resetting Styles...");
                          if (itsMaskExc == "")
                            itsMaskExc = "N.A.";
                            if (itsReplacement == "")
                              itsReplacement = itsStyles[0];
                            try
                            {
                              itsReplacement.name;
                            }
                            catch (e)
                            {
                              itsReplacement = itsStyles[0];
                            }
                            for (var cpt = itsStyles.length-1; cpt >= 0; cpt--)
                            {
                              var myInc = new RegExp(itsMaskInc);
                            var myExc = new RegExp(itsMaskExc);
                              if (myInc.test(itsStyles[cpt].name) && !myExc.test(itsStyles[cpt].name))
                            {
                             try
                             {
                              itsStyles[cpt].remove(itsReplacement);
                             }
                             catch (e)
                             {
                             }
                            }
                          }
                          }

                          ===================

                          • 10. Re: [JS] (CS4) Issue with menuAction "Close"
                            CTC Imaging Level 1

                            Looks like this function from the library (PrePressLIBRARY.jsxinc) was left out in STARTUP.jsx

                             

                            ==================

                            //*** USER Window's Account Name
                            //Parameters:
                            //Return: itsUser. {String}
                            function GetUser()

                            var itsUser = ($.os.substring(0, 7)=="Windows") 
                              ? $.getenv("USERNAME") 
                              : $.getenv("USER"); 
                            return itsUser;
                            }

                            ===================

                            Sorry about that, Alex.

                            • 11. Re: [JS] (CS4) Issue with menuAction "Close"
                              CTC Imaging Level 1

                              As well as this function in STARTUP.jsx

                              ========================

                              //*** Style: Find 1st occurence.
                              //Parameters:
                              //itsStyles: Object/Paragraph/Character Style. {Object}.
                              //itsMaskInclude: Pattern which to INCLUDES (Expression). EMPTY string will be ALL. {RegExp}
                              //itsMaskExclude: Pattern which to EXCLUDES (Expression). EMPTY string will be N.A. {RegExp}
                              //Return: Pointer to Style or -1 if not found.
                              function GetStyle (itsStyles, itsMaskInc, itsMaskExc)
                              {
                                if (itsMaskExc == "")
                                  itsMaskExc = "N.A.";
                              //alert ("GetStyle: "+itsMaskInc+"\nExclude: "+itsMaskExc);
                                for (var cpt = 0; cpt < itsStyles.length; cpt++)
                                {
                                  var myInc = new RegExp(itsMaskInc);
                                  var myExc = new RegExp(itsMaskExc);
                                  if (myInc.test(itsStyles[cpt].name) && !myExc.test(itsStyles[cpt].name))
                                    return (itsStyles[cpt]);
                                }
                                return -1;    //*** If it comes out of the loop it did NOT find
                              }

                              =========================

                              I am so sorry. It's for debugging reason that I excluded the library.

                               

                              I still get the error when listing eventlisteners through EventInfo.

                               

                              In CS4, as part of debugging, I left the Startup Scripts empty.

                              I manually trigger EVENTS,jsx. --> No error, but maybe it's not loading anything!!!

                               

                              Then STARTUP.jsx. ---> Error in EventInfo.

                               

                              That's as far I am in debugging. As mentioned before, CS3 works flawlessly.

                               

                              Alex.

                              • 12. Re: [JS] (CS4) Issue with menuAction "Close"
                                CTC Imaging Level 1

                                Hello Kasyan.

                                I believe I am going crazy. It looks I can load actions, but I can even list the info for each menu I assign them for.

                                 

                                I even wrote a basic testing script and once loaded I can't even remove it!!! Needless to say even listing it. And nothing happens.

                                 

                                Looks like events work though. I ran "getEventInfo.jsx" that was included in CS3 in CS4... just FYI.

                                 

                                Olev if you could help me out as well, I would appreciate. You were the one who set me up correctly in CS3, last year. We discovered together the bug with the Open Event and we circumvented it using Action instead. My all Department relies on those Actions to streamline our workload.

                                Not to discredit you Kasyan, but the more heads together, the better or merrier

                                 

                                Thanks, Alex

                                • 13. Re: [JS] (CS4) Issue with menuAction "Close"
                                  Olav Martin Kvern Level 3

                                  Hi Alex,

                                   

                                  I'm not aware of any big changes in menu action scripting between CS3 and CS4. My first thought is that there's a localization difference between the two versions you've installed--which would mean that "Close" might not be the term you need to target the relevant menu.

                                   

                                  So let's try something really simple:

                                   

                                  #targetengine "session"

                                  //Use the locale-independent version of the name for the close menu action...

                                  var myMenuAction = app.menuActions.item("$ID/$$$/Menu/Close");

                                  var myEventListener = myMenuAction.eventListeners.add("afterInvoke", myEventHandler", false);

                                  function myEventHandler(event){

                                      alert("Looks like you're trying to close a document!");

                                  }

                                   

                                  Does that do anything in your version of InDesign CS4?

                                   

                                  Thanks,

                                   

                                  Ole

                                  • 14. Re: [JS] (CS4) Issue with menuAction "Close"
                                    CTC Imaging Level 1

                                    Sorry I could not respond earlier. I do not have CS4 at home and they are still expecting me to fulfill my usual workload on top of debugging.

                                     

                                    Anyway that works!

                                     

                                    But if you add --- alert (myMenuAction.eventListeners.length); --- after adding the event. It shows 2?!?

                                     

                                    Executing --- myMenuAction.eventListeners[0].remove() --- resets the length to 0!!!

                                    Which explaing why my EventRemove function does not work because of the length discrepency in the reverse loop!

                                     

                                    It also works when replacing with --- var myMenuAction = app.menuActions.item("Close"); ---

                                    But still the same length issue.

                                     

                                    Later in the day... I added new menuActions and they load correctly and their length are CORRECT. Still something weird with "Close"

                                     

                                    Alex.

                                     

                                    addedum.

                                    =======

                                    //*** Remove EventListeners
                                    //Parameters:
                                    //itsEvents: EventListeners to get info on. {Array Object}
                                    //Return: Info. {String}
                                    function EventRemove (itsEvents)
                                    {
                                    for (var cpt = itsEvents.length-1 ; cpt >= 0 ; cpt--)
                                      itsEvents[cpt].remove();
                                    return;
                                    }

                                     

                                     

                                    FYI. Seems my firewall prevents me to attache files!