The script goes through the motions but the make alpha channels fails to materialize. So I changed the the Action manger code that is use to make the alpha channel. All versions of Photoshop then create alpha channels with a selection, However, CC 2017 Alpha channels were the inverses of what the should be. So I added a test for Photoshop and if above CC 2015.5 through in an invert selection. So the script no work with all the version of Photoshop I now have installed. Who know what tomorrow will bring? All versions of Photoshop have bugs. What will Adobe give us next.
#target photoshop
var doc = activeDocument;
setColors ();
for(var i=0;i<doc.pathItems.length;i++){
doc.pathItems.select();
makeSelection ();
//makeChannel ();
n = i+1;
saveAlpha("Alpha " + n);
}
selRGB ();
doc.selection.deselect();
function selRGB(){
var idslct = charIDToTypeID( "slct" );
var desc10 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref5 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idChnl = charIDToTypeID( "Chnl" );
var idRGB = charIDToTypeID( "RGB " );
ref5.putEnumerated( idChnl, idChnl, idRGB );
desc10.putReference( idnull, ref5 );
executeAction( idslct, desc10, DialogModes.NO );
}
function setColors(){
var idRset = charIDToTypeID( "Rset" );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref3 = new ActionReference();
var idClr = charIDToTypeID( "Clr " );
var idClrs = charIDToTypeID( "Clrs" );
ref3.putProperty( idClr, idClrs );
desc3.putReference( idnull, ref3 );
executeAction( idRset, desc3, DialogModes.NO );
}
function makeChannel(){
var idMk = charIDToTypeID( "Mk " );
var desc4 = new ActionDescriptor();
var idNw = charIDToTypeID( "Nw " );
var desc5 = new ActionDescriptor();
var idClrI = charIDToTypeID( "ClrI" );
var idMskI = charIDToTypeID( "MskI" );
var idMskA = charIDToTypeID( "MskA" );
desc5.putEnumerated( idClrI, idMskI, idMskA );
var idClr = charIDToTypeID( "Clr " );
var desc6 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc6.putDouble( idRd, 255.000000 );
var idGrn = charIDToTypeID( "Grn " );
desc6.putDouble( idGrn, 0.000000 );
var idBl = charIDToTypeID( "Bl " );
desc6.putDouble( idBl, 0.000000 );
var idRGBC = charIDToTypeID( "RGBC" );
desc5.putObject( idClr, idRGBC, desc6 );
var idOpct = charIDToTypeID( "Opct" );
desc5.putInteger( idOpct, 50 );
var idChnl = charIDToTypeID( "Chnl" );
desc4.putObject( idNw, idChnl, desc5 );
executeAction( idMk, desc4, DialogModes.NO );
// =======================================================
var idFl = charIDToTypeID( "Fl " );
var desc7 = new ActionDescriptor();
var idUsng = charIDToTypeID( "Usng" );
var idFlCn = charIDToTypeID( "FlCn" );
var idBckC = charIDToTypeID( "BckC" );
desc7.putEnumerated( idUsng, idFlCn, idBckC );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc7.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc7.putEnumerated( idMd, idBlnM, idNrml );
executeAction( idFl, desc7, DialogModes.NO );
}
function makeSelection(){
var idsetd = charIDToTypeID( "setd" );
var desc12 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref6 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref6.putProperty( idChnl, idfsel );
desc12.putReference( idnull, ref6 );
var idT = charIDToTypeID( "T " );
var ref7 = new ActionReference();
var idPath = charIDToTypeID( "Path" );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref7.putEnumerated( idPath, idOrdn, idTrgt );
desc12.putReference( idT, ref7 );
var idVrsn = charIDToTypeID( "Vrsn" );
desc12.putInteger( idVrsn, 1 );
var idvectorMaskParams = stringIDToTypeID( "vectorMaskParams" );
desc12.putBoolean( idvectorMaskParams, true );
executeAction( idsetd, desc12, DialogModes.NO );
}
function saveAlpha(alphaName){
var numberArray = version.split(".");
if ( numberArray[0] > 17 ) {
var idInvs = charIDToTypeID( "Invs" );
executeAction( idInvs, undefined, DialogModes.NO );
}
var idDplc = charIDToTypeID( "Dplc" );
var desc27 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref11 = new ActionReference();
var idChnl = charIDToTypeID( "Chnl" );
var idfsel = charIDToTypeID( "fsel" );
ref11.putProperty( idChnl, idfsel );
desc27.putReference( idnull, ref11 );
var idNm = charIDToTypeID( "Nm " );
desc27.putString( idNm, alphaName );
try {
executeAction( idDplc, desc27, DialogModes.NO );
}
catch(e) {}
}