Copy link to clipboard
Copied
Hello everyone!
I have a script batch to process many scripts:
/*clean Adobe ExtendScript Console Javascript*/if (app.name === "ExtendScript Toolkit") {app.clc();} else {var estApp= BridgeTalk.getSpecifier("estoolkit");if(estApp) {var bt = new BridgeTalk; bt.target = estApp; bt.body = "app.clc()"; bt.send();}}
var thisScript = new File($.fileName);
var containingFolder = new Folder(thisScript.parent.absoluteURI);
//alert("This script is in " + containingFolder.absoluteURI);
var path = containingFolder.absoluteURI;
var appFolder = new Folder(Folder.appPackage.parent.absoluteURI);
//alert("The app folder is at " + Folder.decode(appFolder.absoluteURI));
function batch()
{
var f1 = File ( path+"/01-Index-Add-G-glosary-and-cross-references.jsx" );
var f2 = File ( path+"/02-find-errors-similar-to-Text001.jsx" );
var f3 = File ( path+"/03-Apply-italics-to-all-titles.jsx" );
var f4 = File ( path+"/04-Apply-Roman-to-all-numbers.jsx" );
var f5 = File ( path+"/05-Apply-Roman-to-all-commas.jsx" );
var f6 = File ( path+"/06-Apply-Roman-to-all-G-glosary.jsx" );
var f7 = File ( path+"/07-Apply-Roman-to-all-parenthesis.jsx" );
var f8 = File ( path+"/08-Apply-Roman-to-all-cross-references.jsx" );
var f9 = File ( path+"/09-Clean-all-overrides.jsx" );
$.writeln("_________ Running the Script: " + f1.name + " ________"); app.doScript ( f1 );
$.writeln("_________ Running the Script: " + f2.name + " ________"); app.doScript ( f2 );
$.writeln("_________ Running the Script: " + f3.name + " ________"); app.doScript ( f3 );
$.writeln("_________ Running the Script: " + f4.name + " ________"); app.doScript ( f4 );
$.writeln("_________ Running the Script: " + f5.name + " ________"); app.doScript ( f5 );
$.writeln("_________ Running the Script: " + f6.name + " ________"); app.doScript ( f6 );
$.writeln("_________ Running the Script: " + f7.name + " ________"); app.doScript ( f7 );
$.writeln("_________ Running the Script: " + f8.name + " ________"); app.doScript ( f8 );
$.writeln("_________ Running the Script: " + f9.name + " ________"); app.doScript ( f9 );
}
batch();
to avoid common errors, I would like to take direct the name of the script.jsx, because always my script start with this:
01-
02-
03-
...
I try to do something like this, but didn`t work:
var f1 = File ( path+"/01-*.jsx" );
var f2 = File ( path+"/02-*.jsx" );
var f3 = File ( path+"/03-*.jsx" );
var f4 = File ( path+"/04-*.jsx" );
var f5 = File ( path+"/05-*.jsx" );
var f6 = File ( path+"/06-*.jsx" );
var f7 = File ( path+"/07-*.jsx" );
var f8 = File ( path+"/08-*.jsx" );
var f9 = File ( path+"/09-*.jsx" );
Thanks so much !!!
Hello again,
I made some changes to your script. ATTENTION there are encoded errors
eg "i" and "I" (capital and not capital)
Re bonjour,
J'ai apporté des modifications a votre script. ATTENTION il y a des erreur d’encodé
ex: le "i" et 'I" (capitale et non capitale)
for (i=0; I<list.length; i++){
Voici le script modifier
sortais le script du dossier voir image
.../*clean Adobe ExtendScript Console Javascript*/
//https://forums.adobe.com/thread/2505091
if (app.name === "ExtendScript Toolkit")
{
Copy link to clipboard
Copied
Hi,
If you use Folder.getFiles then you should be able to do what you want.
From the Documentation
folderObj.getFiles ([mask])
mask:
Optional. A search mask for file names. A string that can contain question mark (?) and asterisk (*) wild cards. Default is "*", which matches all file names.
Can also be the name of a function that takes a File or Folder object as its argument. It is called for each file or folder found in the search; if it returns true, the object is added to the return array.
Then just iterate through the array that is returned.
Hope this helps
Malcolm
Copy link to clipboard
Copied
Hello Malcolm!
very useful, I start to do some progress, and now I get the names of the scripts successfully:
function batch()
{
var f1 = File ( path + containingFolder.getFiles ("01-*") );
var f2 = File ( path + containingFolder.getFiles ("02-*") );
$.writeln("_________ Running the Script: " + f1.name + " ________");
app.doScript ( f1 );
$.writeln("_________ Running the Script: " + f2.name + " ________");
app.doScript ( f2 );
}
But looks this line, cannot run using the getFiles function:
app.doScript ( f1 );
Look at my Javascript Console:
Copy link to clipboard
Copied
I think sometimes the folder can have 9 files other time 12, etc...
Maybe is more efficient to run all folder content.
Exist a function to do this?
if exist if important run in order, I mean:
01....
02...
03...
etc...
thanks so much!
Copy link to clipboard
Copied
1. You are reading not a single file, but all files that start with "01-". Look at that console error message! You get a long, long list of files.
Use "01-*.jsx" to get just the JavaScript ones.
2. … which will still throw an error if it finds more than one. In fact I am surprised it does not throw an error on the type of data: "getFiles" returns an array of items, not a single file. You may need to check if "getFiles" returns more than a single file.
3. Except if you want to read multiple files after all, as in your next question. Then just use something like
list = containingFolder.getFiles ("*.jsx"); // list is an ARRAY
list.sort();
for (i=0; I<list.length; i++)
.. run this script
list.sort sorts alphabetically, not numerically, but it will do if you consistently have the correct number of leading zeros as in "01", "02" .. "10", "11" etc.
Copy link to clipboard
Copied
HI,
The getFiles function returns an array of object so you will need to wrap them in a loop, something like
var f1 = containingFolder.getFiles ("01-*") ;
for ( var i = 0; i < f1.length; i++)
{
var curFile = File ( f1 );
app.doScript ( curFile);
}
Hope the helps
Malcolm
Copy link to clipboard
Copied
Hi Malcolm and Jongware,
just to clarify this is my folder, the number of scripts is different each time.
I try to do this, and didn`t work:
/*clean Adobe ExtendScript Console Javascript*/if (app.name === "ExtendScript Toolkit") {app.clc();} else {var estApp= BridgeTalk.getSpecifier("estoolkit");if(estApp) {var bt = new BridgeTalk; bt.target = estApp; bt.body = "app.clc()"; bt.send();}}
var thisScript = new File($.fileName);
var containingFolder = new Folder(thisScript.parent.absoluteURI);
//alert("This script is in " + containingFolder.absoluteURI);
var path = containingFolder.absoluteURI;
var appFolder = new Folder(Folder.appPackage.parent.absoluteURI);
//alert("The app folder is at " + Folder.decode(appFolder.absoluteURI));
function getFileExtension(filename) {
return filename.split('.').pop();
}
function batch()
{
list = containingFolder.getFiles ("*.jsx"); // list is an ARRAY
list.sort();
for (i=0; I<list.length; i++){
var f = File ( path + containingFolder.getFiles (i) );
}
$.writeln("_________ Running the Script: " + f.name + " ________");
app.doScript ( f );
}
batch();
Also I try the Malcolm,
but only change the first script 01-*
and if I do this:
var f1 = containingFolder.getFiles ("*.jsx") ;
I get a error in the line:
app.doScript ( curFile);
Thanks so much!!
Copy link to clipboard
Copied
Hello again,
I made some changes to your script. ATTENTION there are encoded errors
eg "i" and "I" (capital and not capital)
Re bonjour,
J'ai apporté des modifications a votre script. ATTENTION il y a des erreur d’encodé
ex: le "i" et 'I" (capitale et non capitale)
for (i=0; I<list.length; i++){
Voici le script modifier
sortais le script du dossier voir image
/*clean Adobe ExtendScript Console Javascript*/
//https://forums.adobe.com/thread/2505091
if (app.name === "ExtendScript Toolkit")
{
app.clc();
} else {
var estApp= BridgeTalk.getSpecifier("estoolkit");
if(estApp) {
var bt = new BridgeTalk;
bt.target = estApp;
bt.body = "app.clc()";
bt.send();
}
}
var thisScript = File($.fileName);
$.writeln("thisScript " + thisScript.name);
$.writeln("thisScript " + thisScript.path);
var containingFolder = Folder(thisScript.path+"/batch/");
function batch()
{
list = containingFolder.getFiles ("*.jsx"); // list is an ARRAY
$.writeln(" list " + list.length);
list.sort();
for (i=0; i < list.length; i++){
var f = File (list );
$.writeln("_________ Running the Script: " + f.name + " ________");
app.doScript ( f );
}
}
batch();
Copy link to clipboard
Copied
Hi Liphou,
this script is working fantastic!
Thanks so much for your help
Also, thanks to everyone involved in this ticket.
Copy link to clipboard
Copied
Hi,
I can see two possible issues ( I think one of them was in my code)
the for loop has a capital I in it, when it should be small i.
and the var f = shouldn't need the File or path, as it should be a file object already so the code would be
for ( var i = 0; i < list.length; i++)
{
app.doScript ( list );
}
Hope this helps
Malcolm
Copy link to clipboard
Copied
Hi,
I still with the error look:
function batch()
{
list = containingFolder.getFiles ("*.jsx"); // list is an ARRAY
for ( var i = 0; i < list.length; i++){
app.doScript ( list );
}
}
batch();
In Javascript Console the error is in:
app.doScript ( list );
Maybe is because inside the folder is the file 00-Batch-process.jsx and we need exclude with something like:
function batch()
{
list = containingFolder.getFiles ("*.jsx"); // list is an ARRAY
//list.sort();
¿?(list != "00-Batch-process.jsx"){
for ( var i = 0; i < list.length; i++){
app.doScript ( list );
} }
}
batch();