• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Indesign Java Script running error

Guest
Sep 09, 2012 Sep 09, 2012

Copy link to clipboard

Copied

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 ?


TOPICS
Scripting

Views

6.0K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guru , Sep 12, 2012 Sep 12, 2012

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

Votes

Translate

Translate
LEGEND ,
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 10, 2012 Sep 10, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

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

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

Harbs

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

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…

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

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!"

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 11, 2012 Sep 11, 2012

Copy link to clipboard

Copied

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 ?


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Sep 12, 2012 Sep 12, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 12, 2012 Sep 12, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 13, 2012 Sep 13, 2012

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines