Splitting and combining color channels?

So I’m making normal maps and this would be very handy. I know splitting could be done by manually replacing colors, even though it’d be very tedious, but I really have no idea how to combine them back. Is this already a feature? Is there a script that does this?

I also tried writing a script, but it throws an error as soon as I try to loop over the cels in a layer:

local layer = app.activeLayer

if not layer then
	app.alert("No layer found")
elseif layer.isGroup then
	app.alert("Group selected")
elseif app.activeSprite.colorMode ~= ColorMode.RGB then
	app.alert("Sprite is not in rgba color mode")

local cels = layer.cels
local parent = layer.parent

local channelGroup	= parent:newGroup()

local redChannel	= app.activeSprite:newLayer()
local greenChannel	= app.activeSprite:newLayer()
local blueChannel	= app.activeSprite:newLayer()
local alphaChannel	= app.activeSprite:newLayer()

redChannel	.name = layer.name .. " - r"
greenChannel.name = layer.name .. " - g"
blueChannel	.name = layer.name .. " - b"
alphaChannel.name = layer.name .. " - a"

channelGroup.name	= redChannel.name:sub(1, -5) .. " - channels"
redChannel	.parent = channelGroup
greenChannel.parent = channelGroup
blueChannel	.parent = channelGroup
alphaChannel.parent = channelGroup

for cel in cels do -- "attempt to call a CelsObj value"

hi lenerdv05! i don’t know anything about creating normal maps, however the loop at the end should be in this form:

for cel in ipairs(cels) do 
	-- "attempt to call a CelsObj value"