One of the things you can do with javascript that you can't do with applescript is to use the scriptlistener plugin. This plugin is put into the photoshop plugins folder, and when it's there (you don't want to leave it there all the time) it will record pretty much everything you do, much like an action, but it will generate code to a log file on your desktop. I used it for recording running an action and for saving the png. Those parts of the code are in the functions in the script. So I just established a base folder name, a base file name, and a starting counter. The script will then run your action and save a png to that base folder and change the base file name by the counter increasing by one each time. You need to put in the name of your action and the name of the action set into the script.
#target photoshop
var fileName = 'myFile-';
var folderPath = new Folder (Folder.desktop +'/action test/')//create whatever path you want here. Make sure the folder exists!
var doc = activeDocument;
var counter = 1//counter for changing the filename
for (var i=0;i<4;i++){//Change number 4 to whatever number you want it to repeat + 1
runMyAction ("twirl", "Chuck");//put in action name and action set name. This line can be duplicated for different actions.
savePNG ()
counter++
}
function runMyAction(myAction, myActionSet){
var idPly = charIDToTypeID( "Ply " );
var desc25 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref8 = new ActionReference();
var idActn = charIDToTypeID( "Actn" );
ref8.putName( idActn, myAction );//changed to a variable
var idASet = charIDToTypeID( "ASet" );
ref8.putName( idASet, myActionSet );//Changed to a variable
desc25.putReference( idnull, ref8 );
executeAction( idPly, desc25, DialogModes.NO );
}
function savePNG(){
var idsave = charIDToTypeID( "save" );
var desc28 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc29 = new ActionDescriptor();
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIT = charIDToTypeID( "PGIT" );
var idPGIN = charIDToTypeID( "PGIN" );
desc29.putEnumerated( idPGIT, idPGIT, idPGIN );
var idPNGf = charIDToTypeID( "PNGf" );
var idPNGf = charIDToTypeID( "PNGf" );
var idPGAd = charIDToTypeID( "PGAd" );
desc29.putEnumerated( idPNGf, idPNGf, idPGAd );
var idCmpr = charIDToTypeID( "Cmpr" );
desc29.putInteger( idCmpr, 9 );
var idPNGF = charIDToTypeID( "PNGF" );
desc28.putObject( idAs, idPNGF, desc29 );
var idIn = charIDToTypeID( "In " );
desc28.putPath( idIn, new File( folderPath + '/'+ fileName + counter+ ".png" ) );//set folder path and name
var idDocI = charIDToTypeID( "DocI" );
desc28.putInteger( idDocI, 200 );
var idCpy = charIDToTypeID( "Cpy " );
desc28.putBoolean( idCpy, true );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveBegin = stringIDToTypeID( "saveBegin" );
desc28.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
executeAction( idsave, desc28, DialogModes.NO );
}