14 Replies Latest reply: Sep 13, 2012 4:44 AM by Bill joy RSS

    Indesign Java Script running error

    Bill joy Community Member

      Hi 

      I am new in indesign scripting

      I want to create indesign Application using java script and without using ExtendScript ToolKit

      In this case how create app (the application object).

      if i use ExtendScript ToolKit then there is no need to create application object. app is bydefault

      But i do not want to use of ExtendScript ToolKit .

      I want to create simple java script using

      <script type="text/javascript">

      //body

      </script>

      when i run my java script (.js) file then it create indesign Application (instance).

      For example on mac in Apple Script when i run my apple script

      tell application "Adobe InDesign CS5.5"

      set myDocument to make document with properties

      end tell

      in apple script editor which is inbuild with mac, Indesign Application start(create) sucessfully.

      There is no need any ExtendScript ToolKit type tool to run (start) indesign application.
      only script line  tell application "Adobe InDesign CS5.5"   create application instance.

      In VBScript we create application object using this :

      VBScript :Set myInDesign = CreateObject("InDesign.Application")

      In Java Script how create Indesign Application  Object.

      I try to create Indesign Application object but not sucess.

       

      <!DOCTYPE HTML>

      <html>

      <head>

      <title>Testing JavaScript</title>

      </head>

      <body>

      <script type="text/javascript">

      var app = CreateObject("InDesign.Application");

      var myDocument = app.documents.add();

      var myTextFrame = myDocument.pages.item(0).textFrames.add();

      myTextFrame.geometricBounds = ["6p", "6p", "24p", "24p"];

      myTextFrame.contents = "Hello World!";

      </script>

      </body>

      </html>

       

       

      How create Indesign application Object using JavaScript ?

       

       

       

       

       

       


        • 1. Re: Indesign Java Script running error
          Harbs. CommunityMVP

          You seem to be confused. ExtendScript is not embedded in an HTML document. It is saved as an independant file with a js or jsx extension.

           

          You do not need to create an InDesign object. It is created automatically. Refer to the InDesign object using the global app variable.

           

          Harbs

          • 2. Re: Indesign Java Script running error
            Bill joy Community Member

            Thanks Harbs  for reply

            Plz  give me a simple .js example which run without ExtendScript ToolKit  and create Indesign Application and one textframe in it.

            if I save below script as .js extention and run it after double click on it then it give undefined app error.

             

            <script type="text/javascript">

            var app = CreateObject("InDesign.Application");

            var myDocument = app.documents.add();

            var myTextFrame = myDocument.pages.item(0).textFrames.add();

            myTextFrame.geometricBounds = ["6p", "6p", "24p", "24p"];

            myTextFrame.contents = "Hello World!";

            </script>

             

            I  want to create indesign application using java script  but do not want to use ExtendScript ToolKit.

             

            Thanks.

            • 3. Re: Indesign Java Script running error
              Harbs. CommunityMVP

              What do you mean by not using ExtendScript Toolkit? The ESTK is not required. Script files are saved as plain text inside your Script Panel folder and run from the script panel.

               

              Like I said, there's no need to define "app". Here is the full correct version of your script:

               

              var myDocument = app.documents.add(); 
              var myTextFrame = myDocument.pages.item(0).textFrames.add(); 
              myTextFrame.geometricBounds = ["6p", "6p", "24p", "24p"]; 
              myTextFrame.contents = "Hello World!";
              

               

              Are you trying to run the script from outside InDesign?

              • 4. Re: Indesign Java Script running error
                Bill joy Community Member

                Thanks Harbs for reply

                 

                Yes I want to run the script from outside Indesign.

                For example on Mac os  i use appleScript editor to run appleScript

                 

                tell application "Adobe InDesign CS5"

                set myDocument to make document

                end tell

                 

                My Indesign application start sucessfully.

                 

                I want to simply run my java script  and want to create Indesign Application.

                I do not want to put my script in Script Panel folder.

                 

                Like on Mac os , i want to create on window os using java script.

                Simple run script in any java script editor (except ExtendScript ToolKit) and create Application.

                 

                Is it possible  ?

                 

                Thanks

                • 5. Re: Indesign Java Script running error
                  Harbs. CommunityMVP

                  No. ExtendScript can only be run within the host application.

                   

                  You can run an AppleScript which can execute an ExtendScript using do script.

                   

                  Harbs

                  • 6. Re: Indesign Java Script running error
                    Muppet Mark Community Member

                    That's NOT quite correct Harb's… You head the script with the #target and you can double click it in the UI see Toolkit:

                     

                    #target name Defines the target application for this JSX file. The name value is an application specifier; see Application and namespace specifiers. Enclosing quotes are optional.

                    If the Toolkit is registered as the handler for files with the .jsx extension (as it is by default), opening the file opens the target application to run the script. If this directive is not present, the Toolkit loads and displays the script. A user can open a file by double-clicking it in a file browser, and a script can open a file using a File object’s execute method.

                     

                    As of either CS4 or CS5 you need to put the script in a TRUSTED place… on the mac

                     

                    ~/Documents/Adobe Scripts/YourScript.jsx // Then just alias it from that…

                    • 7. Re: Indesign Java Script running error
                      Harbs. CommunityMVP

                      Um.

                       

                      Well, yeah. ESTK can run scripts as well because it's a host application too...

                       

                      If that helps the OP, than you're right, but he specifically said he did not want to run from ESTK.

                      • 8. Re: Indesign Java Script running error
                        Vamitul Community Member

                        from what i understand, he wants to create a standalone app that will use javascript to send some commands to indesign.

                        • 9. Re: Indesign Java Script running error
                          Muppet Mark Community Member

                          Harb's I think you misunderstood me… Head the file with #target indesign not the ESTK… Your snippet plus this will launch Indesign if NOT running and will execute without opening the ESTK

                           

                          #target indesign
                          
                          var myDocument = app.documents.add(); 
                          var myTextFrame = myDocument.pages.item(0).textFrames.add(); 
                          myTextFrame.geometricBounds = ["6p", "6p", "24p", "24p"]; 
                          myTextFrame.contents = "Hello World!"
                          
                          • 10. Re: Indesign Java Script running error
                            bduffy323 Community Member

                            When I tried this I got indesign to open but no new page with a Hello World! written in the textframe. However, when I clicked the script again when indesign WAS open then the page loaded with the textframe.

                            • 11. Re: Indesign Java Script running error
                              Bill joy Community Member

                              Thanks  for Reply

                               

                              When I tried this I got a Script Aleart message.

                              "You are about to run a script in Adobe indesign CS5.5. You should only run script from a trusted source.Do you want to run the script" Yes, No.

                              when I click on yes then Indesign application start sucessfully and create a text frame with Hello World!.If I click on No then Script open in ExtendScript ToolKit.

                               

                              I want to skip (or hide) this Script Aleart message and run the script directly without prompt this Aleart  message.   How hide this Script Aleart message ?


                              • 12. Re: Indesign Java Script running error
                                Muppet Mark Community Member

                                Then you should also read post 6 where I said where the TRUSTED location is… Then you won't get the dialog…

                                • 13. Re: Indesign Java Script running error
                                  Bill joy Community Member

                                  Thank you very much Mark for Quick reply

                                   

                                  I put my script C:\Documents and Settings\Administrator\My Documents\Adobe Scripts\new.jsx  on window os.

                                  It run script  sucessfully without prompt script alert message.

                                   

                                  Thanks.

                                  • 14. Re: Indesign Java Script running error
                                    Bill joy Community Member

                                    Thanks Mark for reply

                                     

                                    I put my script at Trusted location C:\\Documents and Settings\\Administrator\\My Documents\\Adobe Scripts\\NewSript.jsx

                                    Now I want to execute my script using below method but it not execute and return message "No documents open".

                                     

                                    #include "indesign.h"

                                    INDESIGN::_Application oApplication;   

                                    if(oApplication.CreateDispatch(L"InDesign.Application") ==0)  // it start Indesign Application

                                    {

                                            // Dispatch is not created

                                    }

                                    CString ScriptPath =L"C:\\Documents and Settings\\Administrator\\My Documents\\Adobe Scripts\\NewSript.jsx";

                                    oApplication.DoScript(COleVariant(ScriptPath),long(1246973031),covOpti onal,long(1699967573),ScriptPath);

                                     

                                    It prompt message "No document open". While I double click on NewScript.jsx it run sucessfully.

                                    General syntex of  oApplication.DoScript() is

                                    any doScript (script: varies[, language: ScriptLanguage=ScriptLanguage.UNKNOWN][, withArguments: Array of any][, undoMode: UndoModes=UndoModes.SCRIPT_REQUEST][, undoName: string=Script])

                                    Executes the script in the specified language as a single transaction.

                                     

                                    I use long(1246973031) for The java script language.

                                    I do not understand where is problem.

                                    my .jsx file data is

                                     

                                    var myDocument = app.activeDocument;

                                    var myTextFrame = myDocument.pages.item(0).textFrames.add();

                                    myTextFrame.geometricBounds = ["6p", "25p", "30p", "30p"];

                                    myTextFrame.contents = "Adobe Indesign !"

                                     

                                     

                                    Thanks