This script adds every single layer to the background.
Every layer matched with the background is saved by the name of the layer in a directory called with the name of the image.
See: http://krypt77.altervista.org/index_gimp.htm