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

Call another InDesign script with doScript in InDesign CS4 js

Participant ,
Jul 27, 2010 Jul 27, 2010

Hi, I need to call a separate InDesign script from an active script. Could I do it through java script, or do I need to call applescript to run the InDesign script.

var myJavaScript = "myOtherScript";

app.doScript(myJavaScript, ScriptLanguage.javascript);

Thank you.

Yulia

TOPICS
Scripting
14.7K
Translate
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
Engaged ,
Jul 27, 2010 Jul 27, 2010

You can use Apple, VB and JavaScript file within doScript.

Here is an example of calling javascript file within javascript.


var myFile = new File (app.activeScript.parent.fsName + '/abc.jsx');
     if (myFile.exists)
     {
          app.doScript(myFile ,ScriptLanguage.JAVASCRIPT)
     }

Here is Adobe example script where you can see Apple, VB and Javascript calling within Javascript code.

//DoScriptParameters.jsx
//An InDesign CS4 JavaScript
//
//Shows how to send parameters to a script called using
//the doScript method.
main();
function main(){
     var myParameters = ["Hello from DoScript", "Your message here."];
     mySetup();
     mySnippet(myParameters);
     myTeardown();
}
function mySetup(){
}
function mySnippet(myParameters){
     //For JavaScript, the parameters passed to do script must
     //be the same as the parameters passed to the function
     //containing the doScript call.
     //<fragment>
     var myJavaScript = "alert(\"First argument: \" + arguments[0] + \"\\rSecond argument: \" + arguments[1]);";
     app.doScript(myJavaScript, ScriptLanguage.javascript, myParameters);
     if(File.fs == "Windows"){
          var myVBScript = "msgbox arguments(1), vbOKOnly, \"First argument: \" & arguments(0)";
          app.doScript(myVBScript, ScriptLanguage.visualBasic, myParameters);
     }
     else{
          var myAppleScript = "tell application \"Adobe InCopy CS3\\rdisplay dialog(\"First argument\" & item 1 of arguments & return & \"Second argument: \" & item 2 of arguments & return & end tell";
          app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage, myParameters);
     }
     //</fragment>
}
function myTeardown(){
}

Hope it will help you.

Shonky

Translate
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 ,
Jul 27, 2010 Jul 27, 2010

You can even check OS for separat

or for excuting the correct path to run the .

JS.

var fileSep = "/";

//Where fileSep is "/" you can change it though if you are on windows.

if(File.fs=="Windows")
{
     fileSep = "\\";
}

app.doScript (new File(app.activeScript.parent.fsName+fileSep+"My_Script.jsx"),
ScriptLanguage.JAVASCRIPT, activeDoc);

HTH,

Pankaj

Translate
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 ,
Jul 28, 2010 Jul 28, 2010

I much prefer using URI rather than fsName. With URI, you don't need to concern yourself with Win vs. Mac, and you don't need to escape path separators...

Harbs

Translate
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 ,
Jul 28, 2010 Jul 28, 2010

True Harbs.

Using fsName is old time habit :-).

Translate
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
Participant ,
Jul 28, 2010 Jul 28, 2010

I am trying two versions and neither of them work. What am I doing wrong:

var myScriptFile = new File (app.activeScript.parent.fsName + '/PCP_ExportPDF_MU.jsx');
     if (myScriptFile.exists)
     {
          app.doScript(myScriptFile ,ScriptLanguage.JAVASCRIPT)
     }

var myScriptFile = new File (app.activeScript.parent.fsName + '/Applications/Adobe InDesign CS4/Scripts/Scripts Panel/Samples/JavaScript/PCP_ExportPDF_MU.jsx');
     if (myScriptFile.exists)
     {
          app.doScript(myScriptFile ,ScriptLanguage.JAVASCRIPT)
     }

Do I need to give it full path to the file?

Thank you.

Yulia

Translate
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 ,
Jul 28, 2010 Jul 28, 2010

Hey!

Try this:

var myFile = File(app.activeScript.path+'/PCP_ExportPDF_MU.jsx');
if(myFile.exists)app.doScript(myFile, ScriptLanguage.JAVASCRIPT);

tomaxxi

Translate
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
Participant ,
Jul 28, 2010 Jul 28, 2010

Do I need to include path before hand:

var path = "/Applications/Adobe InDesign CS4/Scripts/Scripts Panel/Samples/JavaScript/PCP_ExportPDF_MU.jsx";
var myScriptFile = new File (app.activeScript.path + 'PCP_ExportPDF_MU.jsx');
//var myScriptFile = new File (app.activeScript.parent.path + 'PCP_ExportPDF_MU.jsx');
     if (myScriptFile.exists)
     {
          app.doScript(myScriptFile ,ScriptLanguage.JAVASCRIPT)
     }

or as a argument:


var myScriptFile = new File (app.activeScript.path('/Applications/Adobe InDesign CS4/Scripts/Scripts Panel/Samples/JavaScript/PCP_ExportPDF_MU.jsx') + 'PCP_ExportPDF_MU.jsx');
//var myScriptFile = new File (app.activeScript.parent.path + 'PCP_ExportPDF_MU.jsx');
     if (myScriptFile.exists)
     {
          app.doScript(myScriptFile ,ScriptLanguage.JAVASCRIPT)
     }

Thank you.

Translate
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
Participant ,
Jul 28, 2010 Jul 28, 2010

For some reason the line:

var myScriptFile = new File (app.activeScript.parent.fsName + '/PCP_ExportPDF_MU.jsx');

gives me an error.

And when I try

alert (app.activeScript.parent.fsName)

I get an error too.

I understand that  'app.activeScript.parent.fsName' should give me path to the currect script folder and it's not working.

Thank you.

Translate
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 ,
Jul 28, 2010 Jul 28, 2010

What kind of error you are getting?

Is alert dialog gives you the complete correct path or not?

Anyway, what tomaxii have suggested should work.

var myScriptFile=new File(app.activeScript.parent.fsName+"/PCP_ExportPDF_MU.jsx")

app.doScript (myScriptFile, ScriptLanguage.JAVASCRIPT, activeDoc);

or
even try

app.doScript (new File(app.activeScript.parent.fsName+"/PCP_ExportPDF_MU.jsx"), ScriptLanguage.JAVASCRIPT, activeDoc);

activeDoc is used if you trying execute it on current document.

HTH,

Pankaj

Translate
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
Participant ,
Jul 29, 2010 Jul 29, 2010

It doesn't tell me what the error is, but it stops at "app.doScript(myScriptFile, ScriptLanguage.JAVASCRIPT, activeDoc)" line. I tried couple of other things:


var myScriptFile = new File ("/Applications/Adobe InDesign CS4/Scripts/Scripts Panel/Samples/JavaScript/PCP_ExportPDF_MU.jsx";

     if (myScriptFile.exists)
     {
          app.doScript(myScriptFile, ScriptLanguage.JAVASCRIPT, activeDoc);
     }

var myScriptPath = "/Applications/Adobe InDesign CS4/Scripts/Scripts Panel/Samples/JavaScript/PCP_ExportPDF_MU.jsx";
var myScriptFile = new File (myScriptPath);
     if (myScriptFile.exists)
     {
          app.doScript(myScriptFile, ScriptLanguage.JAVASCRIPT, activeDoc);
     }

I wonder if the spaces in the path could be a problem. When I escape them twice (Adobe\\ InDesign) then it runs through the script without calling the other script and without interruption.

Translate
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
Community Expert ,
Jul 30, 2010 Jul 30, 2010

Try this:

File (app.scriptPreferences.scriptsFolder + "/Samples/JavaScript/PCP_ExportPDF_MU.jsx");

Peter

Translate
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
Participant ,
Jul 30, 2010 Jul 30, 2010

No, we put our scripts into Applications InDesign folder, so the preferences folder for scripts is empty. What else could it be?

Thank you.

Yulia

Translate
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
Community Expert ,
Jul 30, 2010 Jul 30, 2010

You need the path to the application. What you stated is an absolute path. See the JavaScript Tools Guide (available from the ESTK Help menu) for details.

Translate
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
Participant ,
Jul 30, 2010 Jul 30, 2010

I searched for the JavaScript Tools Guide on Adobe website, but nothing came up. Where do I find it.

Thank you.

Yulia

Translate
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
Community Expert ,
Jul 30, 2010 Jul 30, 2010

It's in the Help of the ESTK menu:

tools.png

Translate
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
Participant ,
Jul 30, 2010 Jul 30, 2010

It works, it works perfectly just like you sent it in the beginning:

var myFile = new File (app.activeScript.parent.fsName + '/abc.jsx');
     if (myFile.exists)
     {
          app.doScript(myFile ,ScriptLanguage.JAVASCRIPT)
   

but it has to be run from InDesign itself and not from Toolkit. It might be looking for Toolkit's path instead in that case.

Thank you very much.

Yulia

Translate
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 ,
Jul 31, 2010 Jul 31, 2010

Hey!

When you are working in ESTK, you can link your script to InDesign from drop-down on top, or you can use #target indesign to do the same.

--

tomaxxi

http://indisnip.wordpress.com

Translate
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 ,
Nov 18, 2010 Nov 18, 2010
LATEST

1

Translate
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