//Check if a document is open
if ( documents.length > 0 )
{
var docRef = app.activeDocument;
var custompath = "/Games/Toribash-5.2/custom/#/"; //save path
var savepath;
var tgaSaveOptions = new TargaSaveOptions();
tgaSaveOptions.alphaChannels = true;
tgaSaveOptions.rleCompression = false;
var width = docRef.width.as("px")
var height = docRef.height.as("px")
var tbTexture = docRef.name.substring(0, docRef.name.indexOf('.'));
savepath = custompath + tbTexture + ".tga";
displayDialogs = DialogModes.NO;
docRef.saveAs(new File(savepath), tgaSaveOptions, false, Extension.NONE);
file = null;
tgaOptions = null;
}
else
{
alert( "You must have a document open to save!" );
}