Export Layers Script

Also this discussion may help