[JS] app.menuActions on XMLElement

Hi,
I'm trying to apply italics using xml rules and this method : http://forums.adobe.com/thread/744713
function Italique() {
     this.name = "Italique";
     this.xpath = "//hi[@rend='italic']";
     this.apply = function(myElement, myRuleProcessor){
          with(myElement){
               app.select(myElement);
               app.menuActions.itemByID(119611).invoke();
          return true;
myElement is an XMLElement who contains exactly what I want but at :
app.menuActions.itemByID(119611).invoke();
a javascript error occurs : n° 54 at line 78 of the "glue code.jsx" file.
"Exception Javascript non interceptée : Erreur : Le script n'est pas activé"
In English : the script isn't activated.
I don't know what to do.
Help me please!

Hi,
I figured it out by myself : I wasn't selecting the good object.
With
myElement.texts.item(0).select();it works fine!

Similar Messages

  • [JS IDCS5 Server] app.menuActions.item("Go to Item").invoke();

    I've the following script applies xml attributes values to graphic scale, frame size and offset:
    #include "glue code.jsx";
    main();
    function main(){
    var myDoc = app.activeDocument;
    var myRuleSet = new Array (
    new findObjAttribute("//Afbeelding")
    with(myDoc){
    var elements = xmlElements;
    __processRuleSet(elements.item(0), myRuleSet);
    function findObjAttribute(XPATH){
    this.name = "Afbeelding";
    this.xpath = XPATH;
    this.apply = function(myElement, myRuleProcessor)
    with(myElement){
    try {
    var myXmove=myElement.xmlAttributes.itemByName("yoffset").value;
    var myYmove=myElement.xmlAttributes.itemByName("xoffset").value;
    var myHeight=parseInt(myElement.xmlAttributes.itemByName("height").value);
    var myWidth=parseInt(myElement.xmlAttributes.itemByName("width").value);
    var myScale=parseInt(myElement.xmlAttributes.itemByName("scale").value);
              app.select(myElement);
                try {
                    app.menuActions.item("Go to Item").invoke();
                    }catch(e){};
                    app.selection[0].graphics[0].move(undefined, [myYmove, myXmove]);
                    app.selection[0].geometricBounds = [0, 0, myHeight, myWidth];
                    app.selection[0].graphics[0].horizontalScale = myScale;
                    app.selection[0].graphics[0].verticalScale = myScale;
                app.selection = null;
    catch(e){};
    return true;
    On InDesign Desktop it is working fine. On InDesign Server it is not working!?
    app.menuActions.item("Go to Item").invoke();
    Is the above line not working on InDesign Server because it has no interface? And how to script it to make it work?
    Regards, Sjoerd

    Instead, operate directly on myElement:
    myElement.graphics[0].move(undefined, [myYmove, myXmove]);
    Thanks John, this is the script I use:
    #include "glue code.jsx"
    main();
    function main(){
    if (app.documents.length != 0){
    var myDoc = app.activeDocument;
    var myRuleSet = new Array (
    new findObjAttribute("//image[@scale]")
    with(myDoc){
    var elements = xmlElements;
    __processRuleSet(elements.item(0), myRuleSet);
    else{
    alert("You have no document open!");
    exit();
    function findObjAttribute(XPATH){
    this.name = "findObjAttribute";
    this.xpath = XPATH;
    this.apply = function(myElement, myRuleProcessor)
    //Just to check whether the collect element is selected
    var elmName=myElement.markupTag.name;
    var myScale=parseInt(myElement.xmlAttributes.itemByName("scale").value);
    with(myScale){
    var myRectangle = myElement.xmlContent.parent;
    try {
    myRectangle.graphics[0].horizontalScale = myScale;
         } catch(e){};
    return true;

  • How to Open Find/Change with menuAction

    Hi,
    Read the question carefully I'm asking how to open the Find/Change
    dialog, not how to toggle it.
    Toggling is easy enough:
    app.menuActions.itemByName("$ID/Find/Change...").invoke();
    But if it is open, this will close it, and vice versa.
    I'm wondering if there's any way to specifically make sure it's opened?
    Thanks,
    Ariel

    Hi Ariel,
    This probably won't help but see https://forums.adobe.com/message/4413557#4413557
    If you could perform some action that will fail if the panel is closed then you could use a try catch to determine its state.
    I'll leave it to you to think of what that action would be.
    Trevor

  • MenuActions not enabling in InDesign CS5.5

    Hi Scripters,
    InDesign CS4/CS5 is able to invoke menuActions using the below mentioned javascript code.
    var myMenuAction = app.menuActions.item("$ID/Go to Item");
    try {
        myMenuAction.invoke();
        }catch (err){exit();};
    However when I use the same code in InDesign CS5.5 version, we are encountering  "Action not enabled" error.
    Note: Please select the required XML element from the Structure Panel before running this code.
    Thanks & Regards
    csm_phil

    A related issue, perhaps.  I am trying to toggle Menu options via script, to set a user environment.  To make sure that Window->Tools is checked, this always works:
    try {
         var myTools = app.menuActions.item("Tools").checked;
         catch (e) {}
    if (myTools ==false) {
        try {
         app.menuActions.item("Tools").invoke();
         catch (e) {}
    But I also want to toggle things that lack a checkmark, such as Hide Hidden Characters.
    This returns different results depending on whether a document is open, and sometimes does not toggle the selection (Show/Hide) and returns different values for the .checked call.
    try {
         var myHidden = app.menuActions.item("Hide Hidden Characters").checked;
         catch (e) {alert("Error"); }
      if (myHidden ==false ) {
         try {
          app.menuActions.item("Hide Hidden Characters").invoke();
         catch(e) {}
    Sometimes this returns false, sometimes undefined.  I have done many iterations, also looking for ("Show Hidden Characters").checked
    The original code was written for InCopy.  Any menu item that is truly checked is easily controlled.  The ones that toggle Show/Hide are a mess in both InCopy and InDesign. 
    Am I using the wrong syntax?
    Dick Conrad

  • About the function XMLElement

    This is the code:
    Connected to Oracle9i Enterprise Edition Release 9.2.0.5.0
    Connected as apps
    SQL> SELECT XMLElement("SOURCE",source_name) FROM cux_sign_source;
    SELECT XMLElement("SOURCE",source_name) FROM cux_sign_source
    Access violation at address 6766367A in module 'ORA805.dll'. Read of address 00000068
    SQL>
    So,what does it mean,what can I do for this and why can't I use this function

    Please go through this link hope it will help you in using XMLElement:
    http://www.oracle.com/technology/oramag/oracle/03-may/o33xml.html

  • [JS] menuAction.invoke() working with cs3 but not cs4 :-(

    Hi,
    I wrote a script and chose to call a menu through menuAction.invoke();
    I wanted to use an independant locale string to avoid dealing with localization.
    It works nice on CS3 but just fails in the CS4.
    //I want to fit the window to the spread
    var myMenuAction = app.menuActions.item("$ID/Toolbar Fit in Window");
    myMenuAction.invoke();
    I am really stuck because I have read the indesign CS4 scripting guide carefully on page 119. The given instruction seem to be the same as in the  indesign CS3 scripting guide.
    I can't see what I did wrong and yet, no way to get it working on CS4. Any hint ?
    Thanks in advance,
    Loic

    Hi Peter and John,
    FF is so... tolerant to accept the value of the option as the same as it is displayed in the select list.
    where IE is so... prudence, that we have to explictly tell it
    ie Post Element Text in IE should be like this
    <select id="unit" onchange="TankUnit();" >
    <option> -S-</option>
    <option value="ml"> ml</option>
    <option value="kg"> kg </option>
    </select> Units
    bye
    Srikavi

  • [JS] Problem in findKeyString and menuAction

    Hi,
    I read the scripting guide and try to apply that snippet :
    var myString = "";
    var myMenuAction = app.menuActions.item("Convert to Note");
    var myKeyStrings = app.findKeyStrings(myMenuAction.name);
    if(myKeyStrings.constructor.name == "Array"){
    for(var myCounter = 0; myCounter < myKeyStrings.length; myCounter ++){
    myString += myKeyStrings[myCounter] + "\r";
    else{
    myString = myKeyStrings;
    alert(myString);
    I want to get the independant locale string for my french "Document..." command (New Document basically). But if I replace "Convert to Note" by "Document...", the script just prints an empty string.
    I am not sure at all but all my attempts to findKeyString with strings containing ellipsis just fail.
    Furtherly I want to add a eventListener on that menu but I think this post from Kasyan will be instructive enough.
    The problem is start, at the very beginning, I can't get acces to the native $ID/xxx string for the New Document command :-S
    http://forums.adobe.com/message/1107494#1107494
    Any hint ?
    Thanks for all of you guys helping me through years.
    Loic

    Oh, this is fascinating. It appears to, most of the time, return an & but only if you give it an & as input.
    So, for instance:
    function check(s) {
         $.writeln("for "+s+"\n"+
         "no-&\t" + app.findKeyStrings(s).join("\n\t")+"\n"+
         "&\t" + app.findKeyStrings("&"+s).join("\n\t")+
         "\n");    
    check("Document");
    check("New");
    check("File");
    check("Layout");
    check("Edit");
    check("Open...");
    Produces:
    for Document
    no-&    $ID/TV Document
            $ID/DE_Document
            $ID/Document
            $ID/kDocument
            $ID/kPMDocumentTextKey
            $ID/kPMWOpenDocumentWidgetTextLineIIKey
            $ID/kPMWNewDocumentWidgetTextLineIIKey
    for New
    no-&    $ID/kPMWNewDocumentWidgetTextLineIKey
            $ID/Structure_NewFlyout
    &       $ID/&New
    for File
    no-&
    &       $ID/&File
    for Layout
    no-&    $ID/0x58900kS_LayoutStr [NT]
            $ID/LayoutTabName
            $ID/0x58900kS_LayoutKey
            $ID/FS Layout
            $ID/Layout
    &       $ID/&Layout
    for Edit
    no-&    $ID/Structure_Edit
            $ID/Edit
    &       $ID/&Edit
            $ID/#DIALOG_HyperlinkEdit
    for Open...
    no-&    $ID/kPMOpenDocTextKey
    &       $ID/Open...
            $ID/&Open...
    So, in many cases, findKeyStrings() with an & and without an & both return their respective & and &-less versions of $ID/foo and $ID/&foo. But in some cases, without an & returns wrong unhelpful keystrings that seem to substring match foo. And in other cases, & seems required.
    I don't find any support here for the idea that using & is better than not. Obviously in some cases you are required to use it (File) and in other cases you are required not to use it (Document), and this seems like it must be a bug because who the heck would figure it out,..

  • [js] menuAction corresponding to Cmd-Shift-Click

    Hi,
    I need to now wich menuAction use to add a "block of text". (my inDesign is in French so it may not be "block of text" but it corresponds to the javascript object TextFrame)
    For exemple, to add a page I do this :
    app.menuActions.itemByID(24346).invoke();
    Which id correspond to the action Cmd-Shift-Click ?

    Well,
    For now, I'm doing this :
    var myNewPage = myDocument.pages.add();            
    if (myNewPage.side == PageSideOptions.rightHand) {
         var left = leftPair;
         var right = rightPair;
    else {
         var left = leftImpair;
         var right = rightImpair;
    // Fait le lien entre les 2 pages (la parécédente et celle venant d'être créée)
    var myTextFrameC = myNewPage.textFrames.add({geometricBounds:[top, left, bottom, right]});
    myTextFrameC.previousTextFrame = myDocument.pages.item(i-1).textFrames.item(0);
    And this for every page :  while(myDocument.pages.lastItem().textFrames.item(0).overflows)
    But I need top, left, bottom and right.
    With invoke, I won't need all this (which can avoid mistakes).
    Also, when we have an overflow, we can "take" it (clicking on the red square) and place it on the next text frame while clicking on shift. It will had all : pages, text frames... as long as we need.
    You're telling me I can't do that (this easy) in javascript?
    I don't understand this :
    (any_master_page_item).override(destinationPage);

  • Create New Parent Element

    Hi,
      Im Creating New Parent Element for Xml Elements using the below code.
        app.activeDocument.xmlElements[0].xmlElements[1].select()
         app.menuActions.itemByID(78818).invoke();
    When I using this code, click event for  OK button is not happen.  wats error in this?
    - Sudha K

    Uri,
    Comments below.
    Uri Shani wrote:
    > Ed, I will look up this feature. Yet my strategy is to start from UML,
    > convert to eCore and than reload my genmodel.
    > I suppose that what you suggest would mean to always intervene with
    > the genModel after it is reloaded to modify it, while in my approach -
    > my modifications are agnostic to updates
    No, Reload... preserves all generator settings.
    > I make in the base UML model.
    > I have currently only one "interruption" where I need to modify a
    > certain property as an ID - which I could not find how to do in the
    > UML and have it passed through the above transformations.
    Try exporting your Ecore to UML to see if that's recorded in the profile
    in some way.
    > That I am doing manually on the eCore intermediate representation.
    >
    > Thanks,
    > - Uri

  • Button action with no result

    I like to have a button with the following InDesign (CS6) function: Paste in Place.
    But whatever I try, it did not work.
    app.menuActions.item("$ID/Paste in Place").invoke();
    or
    app.scriptMenuActions.itemByID(273).invoke();
    The Configurator panel I have made is this one (http://www.hansg.nl/screenshot_24.png) and all the buttons works, except the 'Paste in Place' one.
    So, I need some help!
    OS X 10.8.5
    InDesign CS6 8.0.2
    Configurator 4.0.0
    I insert both scripts in two different ways: as a  link to the javascipt and as text in the script file option.
    And  also as an option showed in the left colomn under Menu's" > "Main" > "Edit" > "Paste in Place"

    Thanks for the info.
    Interesting, that they work fine in Preview and on set-top player. I do not have/know WinDVD, so I'm not sure of what problems it might have. I happen to use other software DVD players, and so far, they all work like my set-tops and Preview.
    I'm assuming that when the left-mouse button is over your Button and pushed, nothing happens. Does the Button Highlight? Your described PS work should not have altered the Button's ability to function. If they work elsewhere, they *should* work in a software player. I assume that ALL Buttons exhibit this behavior?
    Maybe someone can help with WinDVD. Might be something very simple, that's just beyond my knowledge.
    Other than to say your Project looks good in detail, I can't really help - sorry.
    Hunt

  • Open up "Save As" dialog in javascript

    Hello all,
         I am a newbie to scripting and to be honest it makes my head hurt lol, Kudos to all that make this look easy. I found some good resources but following everything is going to take a bit. I have am using the object model viewer and its a great resource. Long story even longer I am trying to automate a bunch of repetitive tasks that we have to run on a ton of pre-built documents. I have been hobbling together some code that has been working. everything is working and I can worry about cleaning up the code later (for my sake. I have OCD)
    I can't seem to find a way to open up the "save as" dialog so that the user can save the document to a directory that will change from week to week. The file name will vary across the run of files. I don't need anything to automate that part. I just want it to pop up and then continue the run. I'd like to do this at the start of the script so that when all the changes are made I can just have the document close. (I haven't included the closing code yet) Is this possible? I cant seem to find anything out there to point me in the right direction.
    Here is what I have so far.
    myDoc=app.activeDocument; 
    for (var  n=myDoc.masterSpreads.length-1; n>=0; n--){ 
         if (isMasterSpreadInUse(myDoc.masterSpreads[n])==false){ 
              myDoc.masterSpreads[n].remove(); 
    function isMasterSpreadInUse(myMasterSpread){ 
         var myDoc=myMasterSpread.parent; 
         for (var  n=myDoc.masterSpreads.length-1; n>=0; n--){ 
              if (myDoc.masterSpreads[n].appliedMaster==myMasterSpread){ 
                   return true; 
         for (var  n=myDoc.pages.length-1; n>=0; n--){ 
              if (myDoc.pages[n].appliedMaster==myMasterSpread){ 
                   return true; 
         return false; 
    Array.prototype.filter = function(collection) { 
              var k, i, con, ids = collection.everyItem().id; 
              con: for (k = ids.length - 1; k >=0; k--)  
                        for (i = 0; i < this.length; i++) 
                        if (this[i].id == ids[k]) { 
                             ids.splice(k, 1);  
                             continue con; 
              return ids;     // array with unmatched ids from collection 
    var  
              mL = app.activeDocument.pageItems.everyItem().itemLayer, 
              mUnusedLayersID = mL.filter(app.activeDocument.layers), 
              len = mUnusedLayersID.length; 
    while (len-->0) 
              app.activeDocument.layers.itemByID(mUnusedLayersID[len]).remove();
    var layers = app.activeDocument.layers.everyItem().getElements();
    for(var i=layers.length-1;i>=0;i--){
    if (layers[i].name[0] == "X"){
         layers[i].remove();
    app.documents.everyItem().xmlElements.item(0).xmlElements.everyItem().untag();
    myPreset = app.printerPresets.item("AdQ 8½x11");
    app.activeDocument.print(false, myPreset);
    SaveOptions.YES

    I've suddenly started getting this issue today on SSMS 2008 with Win 7.  I can do Save but as soon as I try Save As the whole thing just locks up.  I get a flashing Save icon in the bottom right corner but no Save dialog and all I can do at
    that point is close the whole thing down using Task Manager.
    Does anyone know if there is a fix for this?

  • [CS3 JS] event crashes InDesign

    Scripting ladies and gentlemen,
    I'm working on this event script that searches for linked PDF files and
    lets the user copy/relink them. Using the afterOpen eventListener however
    crashes InDesign no matter what I do. This is also the case with
    beforeClose. It appears that my function cnvrtPDFlnk is causing the crash
    (I'm able to alert succesfully with the afterOpen event if I //-comment
    the cnvrtPDFLnk(myDocument)).
    Do one of you scripting gurues have a tip?
    #targetengine "session"
    main();
    function main() {
       app.addEventListener("afterOpen", myEventFunction, false);
    function myEventFunction(myEvent) {
       var myDocument = myEvent.parent;
       var label = docLabel(myDocument, "PDFCheck");
       if(label) {
          //myEvent.stopPropagation();
          //myEvent.preventDefault();
          exit();
       else {
          cnvrtPDFLnk(myDocument);
    function docLabel(myDocument, key) {
       var hasLabel = (eval(myDocument.extractLabel(key))?true:false);
       return hasLabel;
    function cnvrtPDFLnk(myDocument) {
       var graphics = myDocument.allGraphics;
       var link; var linkExt; var linkType; var linkPath; var linkPageRef; var myConfirm; var myFolder; var myFile; var myOrgPath;
       var myLinkObjects = [];
       for (var i = 0; i < graphics.length; i++) {        
          link = graphics[i].itemLink;
          linkExt = link.filePath.split('.').pop().toLowerCase(); 
          linkType = link.linkType.toLowerCase();       
          if (linkExt == 'pdf' || linkType.match('pdf') != null) {
             link.show();
             if(myConfirm= confirm(link.name+"\nDo you want to convert this link?")?myLinkObjects.push(link):alert("Link skipped!\n"+link.name));
       if (myLinkObjects.length > 0) {
          myFolder = Folder.selectDialog("Point me to a hotfolder..");
          copyLink(myLinkObjects, myFolder); // run copyLink function - copies links according to myfolder
          if(myConfirm = confirm("Do you want to relink now?")) {
             reLink(myLinkObjects); // run reLink function - relinks according to myFile dialogue
             app.menuActions.item("Fit Page in Window").invoke();
             app.menuActions.item("First Page").invoke();    
       myDocument.insertLabel("PDFCheck", "true");
       }// no links
    }// end cnvrtPDFLnk
    Best regards,
    Rasmus

    Hi Rasmus,
    Here is an example of scripted plug-in — very simple yet useful for me.
    Its goal is to check color settings in InDesign and Photoshop after a document opens. We use two profiles at work: one for the main part of our magazine and another profile for its cover and the inset for another magazine. Sometimes, although rarely, we forget to switch on the correct setting.
    That's where the plug-in comes to the aid. After a document opens it checks if the file name contains certain characters – e.g. if file name starts with "Obl_" that means that this is a cover and the script checks the color settings, if they are not correct it gives warning.
    Here is short description of how to do it:
    Create a new scripted plug-in project from APIDTemplate.indd file.
    Open APID panel
    Enter 'docLoaded' into Event Filter field and press Enter
    Here is the script that does the job (the script file is generated in the same folder as indd-file):
    if (theItem.eventCode == "docLoaded") {
       var gKasmyDoc = app.activeDocument;
       var gKasDocumentName = app.activeDocument.name;
       KasCheckProfile();
       KasinfoFromPS();
    function KasCheckProfile(){
       var myIssueNumber = parseInt(gKasDocumentName.substr(2, 3));
       if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") == null){
          if (app.colorSettings.workingSpaceCMYK != "ISO Web Coated"){
             alert("Внимание! Для газеты должен использоваться провиль \"ISO Web Coated\", а установлен. — " + app.colorSettings.workingSpaceCMYK);
       if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") != null){
          if (app.colorSettings.workingSpaceCMYK != "ImationMatchprn175lpi_avr.icc          "){
             alert("Внимание! Для вшивки должен использоваться провиль \"ImationMatchprn175lpi_avr.icc\", а установлен. — " + app.colorSettings.workingSpaceCMYK);
       else if (gKasDocumentName.substr(0, 4) == "Obl_"){
          if (app.colorSettings.workingSpaceCMYK != "ImationMatchprn175lpi_avr.icc          "){
    //         alert("Внимание! Для обложки должен использоваться провиль \"ImationMatchprn175lpi_avr.icc\", а установлен. — " + app.colorSettings.workingSpaceCMYK);
             if (confirm("Внимание! Для обложки должен использоваться провиль \"ImationMatchprn175lpi_avr.icc\", а установлен. — " + app.colorSettings.workingSpaceCMYK)) {
                app.colorSettings.cmsSettings = "Listovaya Mashina";
    function KasinfoFromPS() {
       var bt = new BridgeTalk;
       bt.target = "photoshop";
       bt.body = "app.colorSettings;"
       bt.onResult = function(resObj) {
          var myResult = resObj.body;
          KascheckPsColorSettings(myResult);
       bt.send();
    function KascheckPsColorSettings(myColorSettings){
       var myIssueNumber = parseInt(gKasDocumentName.substr(2, 3));
       if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") == null){
          if (myColorSettings != "ISO Web Coated"){
             alert("Внимание в Photoshop! Для газеты должен использоваться провиль \"ISO Web Coated\", а установлен. — \"" + myColorSettings + "\"");
       if (gKasDocumentName.substr(0, 2) == "Q_" && myIssueNumber >= 730 && myIssueNumber <= 999 && gKasDocumentName.match("_Vshivka") != null){
          if (myColorSettings != "Listovaya Mashina"){
             alert("Внимание в Photoshop! Для вшивки должен использоваться провиль \"ImationMatchprn175lpi_avr.icc\", а установлен. — \"" + myColorSettings + "\"");
       else if (gKasDocumentName.substr(0, 4) == "Obl_"){
          if (myColorSettings != "Listovaya Mashina"){
             alert("Внимание в Photoshop! Для обложки должен использоваться провиль \"ImationMatchprn175lpi_avr.icc\", а установлен. — \"" + myColorSettings + "\"");
    You can put your own stuff into the script:
    if (theItem.eventCode == "docLoaded") {
    // do your stuff here
    And finally generate the plug-in.
    Kasyan

  • [JS CS3] Show Text Threads

    Does anyone know the syntax to script the View > Show Text Threads command in CS3? It seems that it should be something like:
    app.activeDocument.viewPreferences.showTextThreads
    ...but that isn't in the DOM. I can't seem to locate it. Can this be done?

    Hi Fred,<br /><br />Here's a little function which will retrieve any menu action based on it <br />name (which appears in the UI). It's much quicker to access menus <br />directly (rather than loop), but this is an easy way to find them.<br /><br />function GetMenuAction(name){<br />    var menus = app.menuActions;<br />    for(var i=0;i<menus.length;i++){<br />        var menu = menus[i];<br />        if(menu.name == name){return menu}<br />        }<br />    return null;<br />    }<br /><br />Actually, this works too:<br /><br />menu = app.menuActions.item("Show Text Threads"<br /><br />Harbs

  • [CS3][JS] beforeClose event listener problem

    Hi all,
    I want my script to do the following: every time when a user closes a document, I wish for "Check Spelling..." dialog box to show up and after the user finishes spell-checking, the document should be closed.
    But instead, if I have one document open, I get an error: Error Number: 53762, Error String: Action is not enabled, and if more than one document open, the dialog opens in the wrong document.
    As far as I understand, the problem is that the menu action is invoked AFTER the document has already been closed – it is quite clear that opening the dialog with no documents open makes no sense – that’s why the error occurs.
    Does anybody know how to solve this? Why beforeClose event type doesn’t correspond to its name? The scripting guide states: “beforeClose – Appears after a close-document request is made but before the document is closed.”
    Here is the script:
    #targetengine "session"
    main();
    function main(){
       var myEventListener = app.addEventListener("beforeClose", myCheckSpelling, false);
    function myCheckSpelling(myEvent){
       app.menuActions.item("Check Spelling...").invoke();
    Kasyan

    Thank you Ole.
    I've been at it for about 6 months.
    I am providing 3 modules. All modules are in 1 folder. That's why the ScriptPath & Department variables.
    FYI: app.pdfPlacePreferences.pageNumber was used solved issues with InEvenScript plugin for CS2. That plugin was NOT handling a loop call. To solve it, I've used a variable to turn ON & OFF the handler. "Import" is used in the OPEN script, and that will execute the event!
    1) Startup. I trimmed it for you but I kept the orignal OPEN-Event disabled. See PrePressEVENT.
    2) PrePressTEST. It's a trimmed version of the actual PrePressOPEN. But it makes InDesign crash. FYI: PrePressOPEN works perfectly when triggered manualy (Script Panel).
    3) PrepressEVENT. Disabled in Startup, I am using this one so I can debug the EVENT and do actual work at the same time. Until it crashed of course.
    The window.add() is what makes it crash. Without it, fine. But if removed myDoc = app.activeDocument points to the wrong one!
    Thank you in advance. Hope this is clear enough.
    Module STARTUP
    =====================
    #target indesign
    #targetengine "session"
    app.scriptPreferences.version = 5.0;
    //******************** BEGIN Main ********************
    var myScriptName = app.activeScript.fsName;
    var myScriptPath = app.activeScript.path;
    var myErrorStyle = "*****Error while Updating!"
    var myMsgStyle = "*****No UpDate! (Delete to Reset)";
    var myDept = "PrePress";
    //*** Initialize SCRIPT Variables
    app.scriptArgs.clear();
    app.scriptArgs.set("Department", "PrePress");
    app.scriptArgs.set("ErrorStyle", "*****Error while Updating!");
    app.scriptArgs.set("MsgStyle", "*****No UpDate! (Delete to Reset)");
    app.scriptArgs.set("Event_Path", myScriptPath); //***Path to InEventScript Plug-In
    app.scriptArgs.set("Event_Test", myScriptPath + "/"+myDept+"TEST.jsx"); //*** Debugging MODULE
    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");
    //*** Initialize GLOBAL Variables
    app.pdfPlacePreferences.pageNumber = 1; //***Flag to PREVENT InEventScript Plug-In RECURSIVE (Loop)
    SkipWRDS = new Array;
    //*** REMOVE all EVENTS
    app.eventListeners.everyItem().remove();
    //******************** EVENTS ********************
    //app.addEventListener("afterOpen", EventOpen, false); //STILL INDESIGN CRASH with OPEN !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    var tmp = "List of Events loaded\n----------------------\n";
    var myEvents = app.eventListeners;
    for (var cpt = 0; cpt < myEvents.length; cpt++)
    tmp += "Event : " + myEvents[cpt].parent.name + "\tType: " + myEvents[cpt].eventType + "\n";
    //alert ("\tPREPRESS Area\n\t\==========\n\n"+tmp);
    alert ("\tTEST Area\n\t=======\n\n"+tmp);
    //******************** END Main ********************
    //****************** FUNCTIONS Definitions ********************
    function EventOpen (itsEvent)
    var myExeSrcFile = new File (app.scriptArgs.get("Event_Open"));
    if (myExeSrcFile.exists)
    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!!!
    myExeSrcFile.open ('r:(read)');
    app.doScript(myExeSrcFile, ScriptLanguage.javascript);
    myExeSrcFile.close();
    else
    alert ("Error! Missing File:\n\n" + myExeSrcFile.fsName);
    return;
    Module PrePressTEST
    =====================
    #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();
    if (app.documents.length == 0)
    exit();
    var myDoc = app.activeDocument;
    //*** ALL DOCUMENTS PREFERENCE
    myDoc.textPreferences.showInvisibles = true;
    myDoc.viewPreferences.showRulers = true;
    myDoc.layoutWindows[0].transformReferencePoint = AnchorPoint.centerAnchor;
    alert (myDoc.name);
    //******************** END Main ********************
    Module PrePressEVENT
    =====================
    #target indesign
    #targetengine "session"
    app.scriptPreferences.version = 5.0;
    //******************** BEGIN Main ********************
    var myEvents = app.eventListeners;
    var tmp = "\nList of Events removed\n------------------------\n";
    for (var cpt = myEvents.length-1 ; cpt >= 0 ; cpt--)
    if (myEvents[cpt].eventType == "afterOpen")
    tmp += "Event #" + cpt + "\tType: " + myEvents[cpt].eventType + "\n";
    myEvents[cpt].remove(); //*** There MAY be MORE than 1 instance.
    //******************** EVENTS ********************
    app.addEventListener("afterOpen", EventOpen, false);
    tmp += "\nList of Events loaded\n----------------------\n";
    var myEvents = app.eventListeners;
    for (var cpt = 0; cpt < myEvents.length; cpt++)
    tmp += "Event : " + myEvents[cpt].parent.name + "\tType: " + myEvents[cpt].eventType + "\n";
    alert ("\tTEST Area\n\t=======\n\n"+tmp);
    //******************** END Main ********************
    //****************** FUNCTIONS Definitions ********************
    function EventOpen (itsEvent)
    // app.scriptArgs.set("Event_Listener", itsEvent.parent.toSource()); //*** PASS Argument
    var myExeSrcFile = new File (app.scriptArgs.get("Event_Test"));
    if (myExeSrcFile.exists)
    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)
    EventInfo (itsEvent);
    itsEvent.preventDefault();
    itsEvent.stopPropagation();
    itsEvent.parent.windows.add(); //*** Doc. has no Window!!!
    myExeSrcFile.open ('r:(read)');
    app.doScript(myExeSrcFile, ScriptLanguage.javascript);
    myExeSrcFile.close();
    alert ("Executed...");
    else
    alert ("Error! Missing File:\n\n" + myExeSrcFile.fsName);
    return;
    function EventInfo (itsEvent)
    var myString = "Handling Event: " +itsEvent.eventType;
    myString += "\r\rTarget: " + itsEvent.target + " " +itsEvent.target.name;
    myString += "\rCurrent: " +itsEvent.currentTarget + " " + itsEvent.currentTarget.name;
    myString += "\r\rPhase: " + GetPhaseName(itsEvent.eventPhase );
    myString += "\rCaptures: " +itsEvent.captures;
    myString += "\rBubbles: " + itsEvent.bubbles;
    myString += "\r\rCancelable: " +itsEvent.cancelable;
    myString += "\rStopped: " +itsEvent.propagationStopped;
    myString += "\rCanceled: " +itsEvent.defaultPrevented;
    myString += "\r\rTime: " +itsEvent.timeStamp;
    alert(myString);
    function GetPhaseName(myPhase)
    switch(myPhase){
    case EventPhases.atTarget:
    myPhaseName = "At Target";
    break;
    case EventPhases.bubblingPhase:
    myPhaseName = "Bubbling";
    break;
    case EventPhases.capturingPhase:
    myPhaseName = "Capturing";
    break;
    case EventPhases.done:
    myPhaseName = "Done";
    break;
    case EventPhases.notDispatching:
    myPhaseName = "Not Dispatching";
    break;
    return myPhaseName;

  • [JS CS3] How to load Find/Change dialog?

    Hello,
    Below is a script that uses GREP to find straight apostrophies and then change them to smart (curly) ones. The script invokes the Find/Change dialog so that the user can see what she or he is doing.
    However, if the user last used the Find/Change dialog in the TEXT mode, that is the mode that appears. I want the script to go to the GREP mode. I see that there is code for app.loadFindChangeQuery(queryName, searchMode), but I have no idea what the "queryName" is and how to use it in this script.
    Thanks for any help.
    Tom
    theGrepLoader("~'", "~]");
    function theGrepLoader(grepFindIt, grepChangeIt){
        app.findGrepPreferences = NothingEnum.NOTHING;
        app.changeGrepPreferences = NothingEnum.NOTHING;
        app.findGrepPreferences.findWhat = grepFindIt;
        app.changeGrepPreferences.changeTo = grepChangeIt;
        app.menuActions.item("Find/Change...").invoke();
    }//end theGrepLoader

    Thanks, Peter!
    I appreciate your help but I have found another solution. I am amazed at my own stupidity sometimes. You see, I do my scripting in a very lame sort of way because I have never used Javascript outside of InDesign. As such, I find myself at a disadvantage because the documentation that Adobe provides assumes that you are aware of many of the basics. Case in point: I have always had trouble manipulating strings because I NEVER KNEW that you could search and replace strings! I just could not find examples of this in the Adobe documentation. So here I was in some cases adding temporary textFrames so I could get to my strings as text contents and then removing the temporary textFrames at the end of the script. In this particular case I needed to merge several paragraphs into one paragraph. Now that I know how to search & replace strings, it is so simple to strip away all the paragraph returns (which are included in text contents). I am learning, albeit rather slowly. Thanks again.
    Regards,
    Len Swierski

Maybe you are looking for

  • New Samsung Display

    I've just purchased a new samsung 19" LCD tv (LNT1954) (1440x900) to use with my mac mini. It is hooked up with the supplied DVI to VGA adapter, and from there VGA to the computer. I had an acer (1440x900) resolution (hooked up identically) and it wo

  • Which album is my photo in?

    Hello all, Hopefully this is a simple question. When looking through the photo library, how do I tell which album, if any, a particular photo is currently in? Thanks for your help, Scott

  • Installing & Upgrading iTunes 8.1.1 for Windows

    When installing the new iTunes I get an error that states "Invalid Drive: s:\" My PC does dont have nor has it ever had a s drive. I have tried to upgrade through iTunes and directly from the web site. I am hesitant to uninstall the current version a

  • Only slow charging and none while sleeping

    Hi! I have a 17" 1,67 MHz PB with a charging problem. The time to charge displayed in the menu bar can change from more than 10 hrs to several hundred. When the computer sleeps it doesn't charge at all, although the power adapter light is amber all t

  • Problem with opening Final Cut Pro X

    I had just moved the 'Final Cut Pro' folder with the events and projects from movies into my own folder. I also had just added another desktop (Dunno if that is part of the problem). Since then, when I open FCP, it has a message saying 'The selected