Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
True Harbs.
Using fsName is old time habit :-).
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hey!
Try this:
var myFile = File(app.activeScript.path+'/PCP_ExportPDF_MU.jsx');
if(myFile.exists)app.doScript(myFile, ScriptLanguage.JAVASCRIPT);
tomaxxi
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Try this:
File (app.scriptPreferences.scriptsFolder + "/Samples/JavaScript/PCP_ExportPDF_MU.jsx");
Peter
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
I searched for the JavaScript Tools Guide on Adobe website, but nothing came up. Where do I find it.
Thank you.
Yulia
Copy link to clipboard
Copied
It's in the Help of the ESTK menu:
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
1
Find more inspiration, events, and resources on the new Adobe Community
Explore Now