Skip navigation
Currently Being Moderated

Indesign Java Script running error

Sep 9, 2012 9:21 PM

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 ?

 

 

 

 

 

 


 
Replies
  • Currently Being Moderated
    Sep 10, 2012 3:56 AM   in reply to Bill joy

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 10, 2012 11:11 PM   in reply to Bill joy

    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?

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2012 12:01 AM   in reply to Bill joy

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

     

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

     

    Harbs

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2012 4:26 AM   in reply to Harbs.

    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…

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2012 4:30 AM   in reply to Muppet Mark

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2012 4:34 AM   in reply to Harbs.

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

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2012 5:02 AM   in reply to Harbs.

    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!"
    
     
    |
    Mark as:
  • Currently Being Moderated
    Sep 11, 2012 5:16 AM   in reply to Muppet Mark

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Sep 12, 2012 1:56 AM   in reply to Bill joy

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

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points