Oops, replace the for loop with this one.
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(); doc.activeLayer = marksLayer; loadActiveLayerTransparencyToSelection(); doc.activeLayer = currentLayer; doc.activeChannels = [doc.channels[channelIndex]]; doc.selection.fill(black); doc.selection.deselect(); selectComponentChannel(); newTextLayer.remove();
}