Skip to main content
Known Participant
November 30, 2021
Answered

Running jsx files from another jsx file

  • November 30, 2021
  • 5 replies
  • 1822 views

Hello

 

I have a bunch of scripts that I would like to call from a single "motherscript". Any idea how I could do this please?

 

The child scripts all look like this:

//@target photoshop;
(function() {
/*Script contents goes here*/
})();

The mother script could look something like this:

(function() {
    if (searchKeyword("scriptA")){
    /* load and run file a.jsx */
    }
    if (searchKeyword("scriptB")){
    /* load and run file b.jsx */
    }
    if (searchKeyword("scriptC")){
    /* load and run file c.jsx */
    }
})();

 

How could I load them from motherscript.jsx?

I'm really stuck on this, any help is appreciated. 🙂

This topic has been closed for replies.
Correct answer Kukurykus

Paths on a mac.

5 replies

JJMack
Community Expert
Community Expert
November 30, 2021

Scripts are often interactive they display a dialog or prompt the user for information, settings, select folders, files,  create file lists, before execution.  Some of these script Support being recorded into actions and they will record the information users Passed in their dialog into the Action step being recorded.   When the recorded action is played  the Action Manager will Pass the recorded dialog information to the Script and the script will bypass displaying its dialog and use the pass information. The script is fully automatic this way no user interaction is required. So the Action can be batched.   This type of  Script Work like Photoshop Plug-in that you install into Photoshop's  Plug-in folder.  However they are installed in Photoshop Script folder and these scripts install themselves into  Photoshop as a menu Item usually in Photoshop's menu File>Automate>... .    Photoshop Plug-in scripts like: Fit mage.jsx,  ContactSheetII.jsx, Lens Correct.jsx, Merge To HDR.jsx, Photomerge.jsx and Download like  X's  Image Processor Pro.jsx, My AspectRatioSelection.jsx and LongSidePrintLength.jsx.   A script can use these Scripts interactivity where the script will display the its  dialog for user interaction so users can pass parameters to the Script. Or have the Script be automated by Pass the Plug-in script the Parameters for the scripts dialog so the script will work without requiring user interaction.

The Code I posted From Image Processor showed  how to Pass the Parammeters to the Script like the Action Manager does. Plug-in scripts have headers that describe their dialog's Paramaters.

JJMack
Legend
November 30, 2021

Most programming languages have lots of includes in the file headers. This is an easy way to reference one bit of code from something else and supported in Extendscript. You can also read and write preferences to a common custom space which makes things much easier.

Kukurykus
KukurykusCorrect answer
Legend
November 30, 2021
JebrAuthor
Known Participant
November 30, 2021

Good call! thanks!!

Stephen Marsh
Community Expert
Community Expert
November 30, 2021
Inspiring
November 30, 2021

Seems that this is what I need:

$.evalFile("theJSXfileIWant.jsx"); 

Thank you both for the amazingly fast correct answers. I'm going to have so much fun with this! 😄

JJMack
Community Expert
Community Expert
November 30, 2021

Scripts cans also be Plug-in like Adobe's  plug-in script  File>Automate>Fit Image.jsx...  If you look at the code in Adobe's  Image Processor.. Script you can see how the Script Pass the Action manage message to the Plug-in script to have the document resized to fit within the width and height.

 

// use the fit image automation plug-in to do this work for me
function FitImage( inWidth, inHeight ) {
	if ( inWidth == undefined || inHeight == undefined ) {
		alert( strWidthAndHeight );
		return;
	}
	var desc = new ActionDescriptor();
	var unitPixels = charIDToTypeID( '#Pxl' );
	desc.putUnitDouble( charIDToTypeID( 'Wdth' ), unitPixels, inWidth );
	desc.putUnitDouble( charIDToTypeID( 'Hght' ), unitPixels, inHeight );
	var runtimeEventID = stringIDToTypeID( "3caa3434-cb67-11d1-bc43-0060b0a13dc4" );	
	executeAction( runtimeEventID, desc, DialogModes.NO );
}
JJMack
PECourtejoie
Community Expert
Community Expert
November 30, 2021

Hi! I'm not a scripter, but I would have a look at Davide's other blog entries if this one does not fit the bill: https://www.davidebarranca.com/2014/01/html-panels-tips-2-including-multiple-jsx/