Long code optimizing
Hello,
in the below code its function is to load a tool preset, selecting certain preset, and then delete the whole tool preset to keep the archive clean.
The code is functioning OK except two things - first, it cycles through all the presets which takes time, and second the code looks a bit long.
What I need is if someone kindly could help me optimize(shorten) the code if possible, so the loading, selecting and deleting time to be shorter than now:
function tool_one() {
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled) {
return;
}
var dialogMode = withDialog ? DialogModes.ALL : DialogModes.NO;
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
var desc2 = new ActionDescriptor();
var ref2 = new ActionReference();
var desc3 = new ActionDescriptor();
var ref3 = new ActionReference();
var desc4 = new ActionDescriptor();
var ref4 = new ActionReference();
var desc5 = new ActionDescriptor();
var ref5 = new ActionReference();
var desc6 = new ActionDescriptor();
var ref6 = new ActionReference();
var desc7 = new ActionDescriptor();
var ref7 = new ActionReference();
var desc8 = new ActionDescriptor();
var ref8 = new ActionReference();
var desc9 = new ActionDescriptor();
var ref9 = new ActionReference();
var desc10 = new ActionDescriptor();
var ref10 = new ActionReference();
var desc11 = new ActionDescriptor();
var ref11 = new ActionReference();
var desc12 = new ActionDescriptor();
var ref12 = new ActionReference();
var desc13 = new ActionDescriptor();
var ref13 = new ActionReference();
var desc14 = new ActionDescriptor();
var ref14 = new ActionReference();
var desc15 = new ActionDescriptor();
var ref15 = new ActionReference();
var desc16 = new ActionDescriptor();
var ref16 = new ActionReference();
var desc17 = new ActionDescriptor();
var ref17 = new ActionReference();
var desc18 = new ActionDescriptor();
var ref18 = new ActionReference();
ref1.putProperty(cTID("Prpr"), sTID("toolPreset"));
ref1.putEnumerated(cTID("capp"), cTID("Ordn"), cTID("Trgt"));
ref3.putEnumerated(sTID("toolPreset"), cTID("Ordn"), cTID("Trgt"));
desc1.putReference(cTID("null"), ref1);
desc1.putPath(cTID("T "), new File(app.path + "/Presets/Tools/sixteentools.tpl"));
desc3.putReference(cTID("null"), ref3);
ref2.putName(sTID("toolPreset"), "t_one");
ref4.putName(sTID("toolPreset"), "t_two");
ref5.putName(sTID("toolPreset"), "t_three");
ref6.putName(sTID("toolPreset"), "t_four");
ref7.putName(sTID("toolPreset"), "t_five");
ref8.putName(sTID("toolPreset"), "t_six");
ref9.putName(sTID("toolPreset"), "t_seven");
ref10.putName(sTID("toolPreset"), "t_eight");
ref11.putName(sTID("toolPreset"), "t_nine");
ref12.putName(sTID("toolPreset"), "t_ten");
ref13.putName(sTID("toolPreset"), "t_eleven");
ref14.putName(sTID("toolPreset"), "t_twelve");
ref15.putName(sTID("toolPreset"), "t_thirteen");
ref16.putName(sTID("toolPreset"), "t_fourteen");
ref17.putName(sTID("toolPreset"), "t_fifteen");
ref18.putName(sTID("toolPreset"), "t_sixteen");
desc1.putBoolean(cTID("Appe"), true);
desc2.putReference(cTID("null"), ref2);
desc4.putReference(cTID('null'), ref4);
desc5.putReference(cTID('null'), ref5);
desc6.putReference(cTID('null'), ref6);
desc7.putReference(cTID('null'), ref7);
desc8.putReference(cTID('null'), ref8);
desc9.putReference(cTID('null'), ref9);
desc10.putReference(cTID('null'), ref10);
desc11.putReference(cTID('null'), ref11);
desc12.putReference(cTID('null'), ref12);
desc13.putReference(cTID('null'), ref13);
desc14.putReference(cTID('null'), ref14);
desc15.putReference(cTID('null'), ref15);
desc16.putReference(cTID('null'), ref16);
desc17.putReference(cTID('null'), ref17);
desc18.putReference(cTID('null'), ref18);
executeAction(cTID("setd"), desc1, dialogMode);
executeAction(cTID("slct"), desc2, dialogMode);
executeAction(cTID("Dlt "), desc3, dialogMode);
executeAction(cTID('slct'), desc4, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc5, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc6, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc7, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc8, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc9, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc10, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc11, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc12, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc13, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc14, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc15, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc16, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc17, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
executeAction(cTID('slct'), desc18, dialogMode);
executeAction(cTID('Dlt '), desc3, dialogMode);
}
app.bringToFront();
step1();
};
Thanks.