I had tried something similar and I scrapped it. The script worked but wouldn't execute during batch. I took great care to make sure nothing was UI dependent and tried 2 ways ... Have one file node in the scene and have the script cycle through the files it finds in a folder on every frame change then dumps them in another array that is checked on each cycle so there are no repeats. Then I tried having all the textures in the scene and had the script make a list of those and cycle through them making connections based on the same terms. I even later added a current and previous frame# check. Worked fine within Maya, I'd hit render, then scrub forward, hit render, different texture but still nothing in batch, preFrame, postFrame, preRender etc nothing. I even tried a simple glow increase with each frame and that didn't work so I don't know what I missed.