Skip to main content
Alex Rezvov
Participating Frequently
April 16, 2025
Question

start script from another script

  • April 16, 2025
  • 2 replies
  • 180 views

Hello, everybody!

 

I have 2 scripts: first.jsx & second.jsx

 

In UI in first.jsx I have a Button. If I press to this button, I need to start second.jsx.

How can I start second.jsx? Both scripts are in same folder.

 

first.jsx:

var dlg = new Window("dialog", "Try to start second.jsx");
dlg.testButton = dlg.add("Button", undefined, "start second.jsx");

dlg.testButton.onClick = function(){
    //missing code
}

dlg.show()

 

second.jsx:

alert("second.jsx successfully started")

2 replies

Stephen Marsh
Community Expert
Community Expert
April 17, 2025
Alex Rezvov
Participating Frequently
April 16, 2025

Now, I try this code. It work.

 

var dlg = new Window("dialog", "Try to start second.jsx");
dlg.testButton = dlg.add("Button", undefined, "start second.jsx");

dlg.testButton.onClick = function(){
    var curScr = $.fileName;
    var path = curScr.slice(0, curScr.lastIndexOf("/")+1);
    $.evalFile(path + "second.jsx")
}

dlg.show()
Alex Rezvov
Participating Frequently
April 16, 2025

I think, this code is correct. In this code we don't check existence of "second.jsx":

var dlg = new Window("dialog", "Try to start second.jsx");
dlg.testButton = dlg.add("Button", undefined, "start second.jsx");

dlg.testButton.onClick = function(){
    var curScr = $.fileName;
    var path = File(curScr).parent;
    $.evalFile(path + "/" + "second.jsx")
}

dlg.show()

 

Legend
April 16, 2025

You can get to the enclosing folder with this snippet:

var x = File($.fileName);
var y = Folder(x.parent);