﻿#target photoshop
/*

// BEGIN__HARVEST_EXCEPTION_ZSTRING

<javascriptresource>
<name>TEX Export JPG</name>
<about>Save all root folders as JPGs maps^rby leshiy^rartleshiy.com</about>
<category>_PlaceAtTopCuzISaidSo_DotA</category>
<enableinfo>true</enableinfo>
</javascriptresource>

// END__HARVEST_EXCEPTION_ZSTRING

*/

function TEX_export()
{    
	doc = app.activeDocument;
	root = Folder( doc.path + "/" + ( doc.name.substr( 0, doc.name.lastIndexOf('.') ) ) );
	saveOptions = new JPEGSaveOptions();	
	saveOptions.matte = MatteType.NONE;
	saveOptions.quality = 10;
	saveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
	
	
	// hide all falders
	var maps = doc.layerSets;
	var	mapsPast = new Array();
    for( i = 0; i < (maps.length); i++ ) {     
         
		mapsPast[i] = maps[i].visible;
		if ( maps[i].visible ) {
           		   
			targetFile = File( root +  "_" + maps[i].name + ".jpg" );
			doc.saveAs( targetFile, saveOptions, true, Extension.LOWERCASE );
			maps[i].visible = false;
		}
   } 
	  
	// RESTORE
    for( i = 0; i < (maps.length); i++ ) {
		maps[i].visible = mapsPast[i]; 
	}
}

TEX_export()