Here's a script that will save the current document as a jpg, with various ways to do so. the way it's set up now will take the text from the source folder from the UI and use that. Line 47 is using the variable of the actual folder path. Line 48 is using the file's full path. In all instances, you have to strip off the extension and put the jpg extension on the path name. This is done with the split('.').
#target photoshop
var doc = activeDocument
var filePath = new Folder(doc.path)
var fileFull = new File(doc.fullName)
var fileName = doc.name.split('.')[0]
var fullNameNoExt = fileFull.fsName.split('.')[0];
var srcFolder = new Folder('/c/');
var holdFolder = new Folder();//to check is the select a folder function is cancled
var dlg = new Window('dialog','Path test');
dlg.sText = dlg.add('statictext',undefined,srcFolder.fsName);
dlg.sText.size=[600,20]
dlg.folderBtn = dlg.add('button',undefined,'Select Folder');
dlg.saveBtn = dlg.add('button',undefined,'Save as jpg');
dlg.saveBtn.onClick = function(){
save ()
dlg.close();
}
dlg.folderBtn.onClick = function(){
holdFolder = new Folder(srcFolder);
holdFolder = Folder.selectDialog('Select a folder to process', srcFolder);
if(holdFolder){srcFolder = holdFolder};
dlg.sText.text = srcFolder.fsName;
};
dlg.show()
function save(){
var idsave = charIDToTypeID( "save" );
var desc9 = new ActionDescriptor();
var idAs = charIDToTypeID( "As " );
var desc10 = new ActionDescriptor();
var idEQlt = charIDToTypeID( "EQlt" );
desc10.putInteger( idEQlt, 8 );
var idMttC = charIDToTypeID( "MttC" );
var idMttC = charIDToTypeID( "MttC" );
var idNone = charIDToTypeID( "None" );
desc10.putEnumerated( idMttC, idMttC, idNone );
var idJPEG = charIDToTypeID( "JPEG" );
desc9.putObject( idAs, idJPEG, desc10 );
var idIn = charIDToTypeID( "In " );
desc9.putPath( idIn, new File( dlg.sText.text +'/'+ fileName +'.jpg' ) );
//desc9.putPath( idIn, new File( filePath +'/'+ fileName +'.jpg' ) );
//desc9.putPath( idIn, new File( fullNameNoExt +'.jpg' ) );
var idDocI = charIDToTypeID( "DocI" );
desc9.putInteger( idDocI, 560 );
var idCpy = charIDToTypeID( "Cpy " );
desc9.putBoolean( idCpy, true );
var idsaveStage = stringIDToTypeID( "saveStage" );
var idsaveStageType = stringIDToTypeID( "saveStageType" );
var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
desc9.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
executeAction( idsave, desc9, DialogModes.NO );
}