Skip to main content
Alex Rezvov
Participating Frequently
Apr 16, 2025 4:22 PM UTC
Question

start script from another script

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

4 replies

Stephen Marsh
Community Expert
Community Expert
Apr 17, 2025 3:49 AM UTC

Similar ways also documented here:

 

https://gist.github.com/MarshySwamp/eb36460ae2813b6fc47e2d3fec48deb3

Translate
Alex Rezvov
Participating Frequently
Apr 16, 2025 5:06 PM UTC

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()
Translate
Alex Rezvov
Participating Frequently
Apr 16, 2025 5:58 PM UTC

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()

 

Translate
Legend
Apr 16, 2025 6:25 PM UTC

You can get to the enclosing folder with this snippet:

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