Yea, that worked. I recorded the AM code using the menu item for fill rather than the KBSC, so I was able to turn on preserve transparency. No need to lock the layer.
#target photoshop
var doc = activeDocument;
var curLayer = doc.activeLayer;//layer to fill
if(curLayer.name !='sample'){
var samp = doc.layers.getByName('sample'); //color sampler layer must be named "sample"
var base = doc.layers.getByName('base'); //layer from which to sample the color"
var sampLocation = new Array((samp.bounds[2].value+samp.bounds[0].value)/2,(samp.bounds[3].value+samp.bounds[1].value)/2)// get location of dot layer for color sampler
doc.activeLayer = base; //select base to sample and just turn on it's visibility
turnOff ();
sampleColor ();
turnOff ();
doc.activeLayer = curLayer;
fillLayer ();
}
else{alert('Do not use the "sample" layer as a starting point')}
function fillLayer(){
var idFl = charIDToTypeID( "Fl " );
var desc5 = new ActionDescriptor();
var idUsng = charIDToTypeID( "Usng" );
var idFlCn = charIDToTypeID( "FlCn" );
var idFrgC = charIDToTypeID( "FrgC" );
desc5.putEnumerated( idUsng, idFlCn, idFrgC );
var idOpct = charIDToTypeID( "Opct" );
var idPrc = charIDToTypeID( "#Prc" );
desc5.putUnitDouble( idOpct, idPrc, 100.000000 );
var idMd = charIDToTypeID( "Md " );
var idBlnM = charIDToTypeID( "BlnM" );
var idNrml = charIDToTypeID( "Nrml" );
desc5.putEnumerated( idMd, idBlnM, idNrml );
var idPrsT = charIDToTypeID( "PrsT" );
desc5.putBoolean( idPrsT, true );
executeAction( idFl, desc5, DialogModes.NO );
}
function turnOff(){
var idShw = charIDToTypeID( "Shw " );
var desc3 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var list2 = new ActionList();
var ref2 = new ActionReference();
var idLyr = charIDToTypeID( "Lyr " );
var idOrdn = charIDToTypeID( "Ordn" );
var idTrgt = charIDToTypeID( "Trgt" );
ref2.putEnumerated( idLyr, idOrdn, idTrgt );
list2.putReference( ref2 );
desc3.putList( idnull, list2 );
var idTglO = charIDToTypeID( "TglO" );
desc3.putBoolean( idTglO, true );
executeAction( idShw, desc3, DialogModes.NO );
}
function sampleColor(){
doc.colorSamplers.removeAll();
colorS1 = doc.colorSamplers.add (sampLocation);
var c1R = colorS1.color.rgb.red
var c1G = colorS1.color.rgb.green
var c1B = colorS1.color.rgb.blue
var idsetd = charIDToTypeID( "setd" );
var desc17 = new ActionDescriptor();
var idnull = charIDToTypeID( "null" );
var ref4 = new ActionReference();
var idClr = charIDToTypeID( "Clr " );
var idFrgC = charIDToTypeID( "FrgC" );
ref4.putProperty( idClr, idFrgC );
desc17.putReference( idnull, ref4 );
var idT = charIDToTypeID( "T " );
var desc18 = new ActionDescriptor();
var idRd = charIDToTypeID( "Rd " );
desc18.putDouble( idRd, c1R );
var idGrn = charIDToTypeID( "Grn " );
desc18.putDouble( idGrn, c1G );
var idBl = charIDToTypeID( "Bl " );
desc18.putDouble( idBl, c1B );
var idRGBC = charIDToTypeID( "RGBC" );
desc17.putObject( idT, idRGBC, desc18 );
var idSrce = charIDToTypeID( "Srce" );
desc17.putString( idSrce, """photoshopPicker""" );
executeAction( idsetd, desc17, DialogModes.NO );
}