This will put the name of the channel in the top right corner of each channel. I tried to comment where and how you can modify it to meet your needs but if you have any questions let me know. It should work with Grayscale, RGB, CMYK, or Lab mode and with any ruler unit execpt percent.
// the color used for the text
var black = new SolidColor();
black.rgb.hexValue = '000000';
var doc = app.activeDocument;
var currentLayer = doc.activeLayer;
var textLayer = doc.artLayers.add();
textLayer.kind = LayerKind.TEXT;
// font requires the postscript name of the font
textLayer.font = "ArialMT";
textLayer.textItem.size = new UnitValue(9,'pt');
textLayer.textItem.justification = Justification.RIGHT;
// set the position for the text. this sets to top right corner of the channel
// here it is set so the text baseline ends 40pts from the right edge, 15pts down
textLayer.textItem.position = [new UnitValue(doc.width.as('pt')-50,'pt'),new UnitValue(15,'pt')];
textLayer.textItem.contents = 'label';// temp label string
for(var channelIndex = 0; channelIndex<doc.channels.length; channelIndex++){ var newTextLayer = textLayer.duplicate(); doc.activeLayer = newTextLayer; newTextLayer.textItem.contents = doc.channels[channelIndex].name; loadActiveLayerTransparencyToSelection(); doc.activeLayer = currentLayer; doc.activeChannels = [doc.channels[channelIndex]]; doc.selection.fill(black); doc.selection.deselect(); selectComponentChannel(); newTextLayer.remove();
}
textLayer.remove();
function loadActiveLayerTransparencyToSelection() {
var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putProperty( charIDToTypeID('Chnl'), charIDToTypeID('fsel') ); desc.putReference( charIDToTypeID('null'), ref ); var ref = new ActionReference(); ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), charIDToTypeID('Trsp') ); desc.putReference( charIDToTypeID('T '), ref ); executeAction( charIDToTypeID('setd'), desc, DialogModes.NO );
};
function selectComponentChannel() { try{ var map = {} map[DocumentMode.GRAYSCALE] = charIDToTypeID('Blck'); map[DocumentMode.RGB] = charIDToTypeID('RGB '); map[DocumentMode.CMYK] = charIDToTypeID('CMYK'); map[DocumentMode.LAB] = charIDToTypeID('Lab '); var desc = new ActionDescriptor(); var ref = new ActionReference(); ref.putEnumerated( charIDToTypeID('Chnl'), charIDToTypeID('Chnl'), map[app.activeDocument.mode] ); desc.putReference( charIDToTypeID('null'), ref ); executeAction( charIDToTypeID('slct'), desc, DialogModes.NO ); }catch(e){}
};