Skip to main content
Gotta Dance
Inspiring
December 29, 2021
Answered

Nesting JSX Scripts

  • December 29, 2021
  • 6 replies
  • 1693 views

Hi everybody,

 

I have two scripts: 1) Select All Layers 2) Ungroup Artboards.

 

Now I can put them sequentially in one script, but what if I want to use and chain Select All Layers with a different script in the folder? I have to either comment out Ungroup Artboards and write below it or copy the Select All Layers to a different script.

 

Is there a way to nest, or @include these scripts collectively into one script, similarly maybe in the fashino mixins are used within SCSS? That way I can modularly pull from an array of scripts into one master sequence without having to copy/paste a bunch of stuff.

 

Granted, no variable passing would come into question, at least that not what I'm venturing to do at the moment.

 

Thanks for any syntax suggestions!!

 

 

 

This topic has been closed for replies.
Correct answer Kukurykus

 

$.evalFile(File($.fileName).path + '/Polyfill.jsx')

 

6 replies

Stephen Marsh
Community Expert
Community Expert
January 3, 2022

I just stumbled over this when looking for something else, although answered it can't hurt to pool the knowledge:

 

http://www.tranberry.com/photoshop/photoshop_scripting/tips/include.html

 

Kukurykus
Legend
January 3, 2022

That's the article created before 'evalFile' made '#include' deprecated.

Inspiring
December 30, 2021

Make a new file and put this code in:

 

#target photoshop;
$.evalFile(new File(./selectAllLayers.jsx));
$.evalFile(new File(./ungroupArtBoards.jsx));

 

Remember to verify that ./selectAllLayers.jsx points to the correct location of that file.

 

If you need to modify the path, a good starting point is using something from Kukurykys' reply:

($.fileName).path

It gives you the complete path to the new script file from where you could point to your selectAllLayers.jsx.

 

Hope it helps!

Kukurykus
Legend
December 30, 2021

How that's possible you have 2nd same named username: jefbr

 

btw your samples don't have quotation marks, plus don't work.

Inspiring
December 30, 2021

What the ? I honestly don't know how this keeps happening. I just want my one account.

Do you have any idea how I can merge/close accounts and/or keep this from happening?

I'll try modifying my post.

Stephen Marsh
Community Expert
Community Expert
December 29, 2021
Kukurykus
KukurykusCorrect answer
Legend
December 29, 2021

 

$.evalFile(File($.fileName).path + '/Polyfill.jsx')

 

Gotta Dance
Inspiring
January 1, 2022

So in the online scripting guide it shows your example above: 

 

https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object.html?highlight=evalfile#evalfile

 

It also shows Stephen's example below as well using a simple @include:

https://extendscript.docsforadobe.dev/extendscript-tools-features/preprocessor-directives.html

 

What is the sense in using | not-using the evalFile command upon loading a JSX script? Why would I make that decision in stacking files? 

 

 

Kukurykus
Legend
January 1, 2022

More reliable $.evalFile() method was introduced to scripting from CS3, so when #include already was in use and in some cases could make problems you needed workarounds for.

Gotta Dance
Inspiring
December 29, 2021

Yeah, modules I imagine is the keyword. I'm looking to make my scripting modular. So to do so would look something like..

 

#include setup_psd.jsx

#include sizing_160x600.jsx

#include bg_borders.jsx

etc. 

at the header, then add any additional customary scripting below in the body.

 

I think it's called stacking, but I'm not sure. 

Legend
December 29, 2021

I'm not sure what you are trying to do, for example do you want a dialog asking which script to run next? One script can call another, scripts can read/write to files or system preferences for persistent values, or you can declare objects and use those for cross-script access. #include will put one script inline with others, I use that for common code in my script utility pack. So you can have variations with different modules included.