try{
    var idsave = charIDToTypeID( "save" );
        var desc27 = new ActionDescriptor();
        var idAs = charIDToTypeID( "As  " );
            var desc28 = new ActionDescriptor();
            var idEQlt = charIDToTypeID( "EQlt" );
            desc28.putInteger( idEQlt, 10 );
            var idOptm = charIDToTypeID( "Optm" );
            desc28.putBoolean( idOptm, true );
            var idMttC = charIDToTypeID( "MttC" );
            var idMttC = charIDToTypeID( "MttC" );
            var idNone = charIDToTypeID( "None" );
            desc28.putEnumerated( idMttC, idMttC, idNone );
        var idJPEG = charIDToTypeID( "JPEG" );
        desc27.putObject( idAs, idJPEG, desc28 );
        var idIn = charIDToTypeID( "In  " );
        desc27.putPath( idIn, savePath() );
        var idDocI = charIDToTypeID( "DocI" );
        desc27.putInteger( idDocI, 195 );
        var idLwCs = charIDToTypeID( "LwCs" );
        desc27.putBoolean( idLwCs, true );
        var idsaveStage = stringIDToTypeID( "saveStage" );
        var idsaveStageType = stringIDToTypeID( "saveStageType" );
        var idsaveBegin = stringIDToTypeID( "saveBegin" );
        desc27.putEnumerated( idsaveStage, idsaveStageType, idsaveBegin );
    executeAction( idsave, desc27, DialogModes.ALL );

    // =======================================================
    var idsave = charIDToTypeID( "save" );
        var desc29 = new ActionDescriptor();
        var idAs = charIDToTypeID( "As  " );
            var desc30 = new ActionDescriptor();
            var idEQlt = charIDToTypeID( "EQlt" );
            desc30.putInteger( idEQlt, 10 );
            var idOptm = charIDToTypeID( "Optm" );
            desc30.putBoolean( idOptm, true );
            var idMttC = charIDToTypeID( "MttC" );
            var idMttC = charIDToTypeID( "MttC" );
            var idNone = charIDToTypeID( "None" );
            desc30.putEnumerated( idMttC, idMttC, idNone );
        var idJPEG = charIDToTypeID( "JPEG" );
        desc29.putObject( idAs, idJPEG, desc30 );
        var idIn = charIDToTypeID( "In  " );
        desc29.putPath( idIn, savePath() );
        var idDocI = charIDToTypeID( "DocI" );
        desc29.putInteger( idDocI, 195 );
        var idLwCs = charIDToTypeID( "LwCs" );
        desc29.putBoolean( idLwCs, true );
        var idsaveStage = stringIDToTypeID( "saveStage" );
        var idsaveStageType = stringIDToTypeID( "saveStageType" );
        var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
        desc29.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
    executeAction( idsave, desc29, DialogModes.NO );
          } catch(e){}

          
function savePath()
  {
    
  try{
      app.activeDocument.path;
      return app.activeDocument.path;
      }catch(e){return Folder.myDocuments}

  }          