I am working on a GIF animation script for Photoshop CS6 (it should also work for CC). One feature I want to add is removing fringing from each layer. I do this by making a layer mask followed by making a contracting selection modifier on the mask. Currently my script works, but it only applies this mask adjustment on the first layer. Is there a native way of running or recording specified actions to be applied on each layer of an opened document? I installed a script that does this but I don't want to call and run it externally in my script. My primary goal is to have everything consolidated into a single action script.
Using Xtoolkit, I have converted my recorded actions into a JSX script. Here is my unaltered version:
#target photoshop
//
// MakeLoopingGIF.jsx
//
//
// Generated Thu Apr 18 2019 01:31:08 GMT-0600
//
cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };
//
//==================== Make Looping GIF ==============
//
function MakeLoopingGIF() {
// Delete
function step1(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(sTID("animationClass"), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
executeAction(cTID('Dlt '), desc1, dialogMode);
};
function RemoveFringe(){
// Set
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
var ref2 = new ActionReference();
ref2.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Trsp'));
ref2.putName(cTID('Lyr '), "Layer 1");
desc1.putReference(cTID('T '), ref2);
executeAction(cTID('setd'), desc1, dialogMode);
};
var doc = app.activeDocument;
// Make
function step3(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putClass(cTID('Nw '), cTID('Chnl'));
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
desc1.putReference(cTID('At '), ref1);
desc1.putEnumerated(cTID('Usng'), cTID('UsrM'), cTID('RvlS'));
executeAction(cTID('Mk '), desc1, dialogMode);
};
// Set
function step4(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
var ref2 = new ActionReference();
ref2.putEnumerated(cTID('Chnl'), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('T '), ref2);
executeAction(cTID('setd'), desc1, dialogMode);
};
// Contract
function step5(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('By '), cTID('#Pxl'), 1);
executeAction(cTID('Cntc'), desc1, dialogMode);
};
// Inverse
function step6(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(cTID('Invs'), undefined, dialogMode);
};
// Delete
function step7(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(cTID('Dlt '), undefined, dialogMode);
};
// Set
function step8(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
desc1.putEnumerated(cTID('T '), cTID('Ordn'), cTID('None'));
executeAction(cTID('setd'), desc1, dialogMode);
};
// Delete
function step9(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Chnl'), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('Aply'), true);
executeAction(cTID('Dlt '), desc1, dialogMode);
};
for (var i=0;i<doc.layers.length;i++){
doc.activeLayer=doc.layers[i];
RemoveFringe();//
};
// Select All Layers
function step10(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
executeAction(sTID('selectAllLayers'), desc1, dialogMode);
};
// Duplicate
function step11(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
desc1.putInteger(cTID('Vrsn'), 5);
executeAction(cTID('Dplc'), desc1, dialogMode);
};
// Reverse
function step12(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
executeAction(sTID('reverse'), desc1, dialogMode);
};
// Make Frames from Layers
function step13(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
executeAction(sTID('animationFramesFromLayers'), desc1, dialogMode);
};
step1(); // Delete
step2(); // Set
step3(); // Make
step4(); // Set
step5(); // Contract
step6(); // Inverse
step7(); // Delete
step8(); // Set
step9(); // Delete
step10(); // Select All Layers
step11(); // Duplicate
step12(); // Reverse
step13(); // Make Frames from Layers
};
//=========================================
// MakeLoopingGIF.main
//=========================================
//
MakeLoopingGIF.main = function () {
MakeLoopingGIF();
};
MakeLoopingGIF.main();
// EOF
"MakeLoopingGIF.jsx"
// EOF
Here is the layer mask method I need to loop for all layers in the active document:
function RemoveFringe(){
// Set
function step2(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
var ref2 = new ActionReference();
ref2.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Trsp'));
ref2.putName(cTID('Lyr '), "Layer 1");
desc1.putReference(cTID('T '), ref2);
executeAction(cTID('setd'), desc1, dialogMode);
};
var doc = app.activeDocument;
// Make
function step3(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putClass(cTID('Nw '), cTID('Chnl'));
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
desc1.putReference(cTID('At '), ref1);
desc1.putEnumerated(cTID('Usng'), cTID('UsrM'), cTID('RvlS'));
executeAction(cTID('Mk '), desc1, dialogMode);
};
// Set
function step4(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
var ref2 = new ActionReference();
ref2.putEnumerated(cTID('Chnl'), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('T '), ref2);
executeAction(cTID('setd'), desc1, dialogMode);
};
// Contract
function step5(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
desc1.putUnitDouble(cTID('By '), cTID('#Pxl'), 1);
executeAction(cTID('Cntc'), desc1, dialogMode);
};
// Inverse
function step6(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(cTID('Invs'), undefined, dialogMode);
};
// Delete
function step7(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
executeAction(cTID('Dlt '), undefined, dialogMode);
};
// Set
function step8(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putProperty(cTID('Chnl'), sTID("selection"));
desc1.putReference(cTID('null'), ref1);
desc1.putEnumerated(cTID('T '), cTID('Ordn'), cTID('None'));
executeAction(cTID('setd'), desc1, dialogMode);
};
// Delete
function step9(enabled, withDialog) {
if (enabled != undefined && !enabled)
return;
var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
var desc1 = new ActionDescriptor();
var ref1 = new ActionReference();
ref1.putEnumerated(cTID('Chnl'), cTID('Ordn'), cTID('Trgt'));
desc1.putReference(cTID('null'), ref1);
desc1.putBoolean(cTID('Aply'), true);
executeAction(cTID('Dlt '), desc1, dialogMode);
};
for
loop for app.activeDocument.layers.length :)Add Menu Item