1 Reply Latest reply on Apr 20, 2016 5:09 AM by natrev

    Create folder in last used folder loacation (aka current folder)

    salvadorr76775311

      HI,

       

      I am stuck with a part of my script.

       

      After the script has done a whol lot of work to multiple files I would like it to run the following script tosave a jpeg of the file in a folder called Print. This folder needs to be created in the current folder that was last used by photoshop. I looked in the discussion boards but could not find what I needed.

       

      I tried the:

      // getting the name and location;  
      var docName = thedoc.name;  
      if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}  
      else {var basename = docName};  
      // getting the location, if unsaved save to desktop;  
      try {var docPath = thedoc.path}  
      catch (e) {var docPath = "~/Desktop"};  
      // create folder if it does not exist;  
      var folderString = docPath+"/"+basename;  
      if (Folder(folderString).exists == false) {new Folder(folderString).create()};  
      

      But this only works if the file has already been saved somewhere. This is not the case and I also do nit want to save the PSD first.

       

      So I Tried the folder.current approach but I do not get the results I am looking for. Any help would be appreciated.

       

       

      var idsave = charIDToTypeID( "save" );
      var desc9 = new ActionDescriptor();
      var idAs = charIDToTypeID( "As  " );
      var desc10 = new ActionDescriptor();
      var idEQlt = charIDToTypeID( "EQlt" );
      desc10.putInteger( idEQlt, 12 );
      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  " );
      //========================================================================================
      var basePath = Folder.current; 
      var folderString = new Folder(basePath + "/Print");
      if (Folder(folderString).exists == false) {new Folder(folderString).create()};
      //========================================================================================
      desc9.putPath( idIn, new File( "" ) );
      var idDocI = charIDToTypeID( "DocI" );
      desc9.putInteger( idDocI, 35 );
      var idsaveStage = stringIDToTypeID( "saveStage" );
      var idsaveStageType = stringIDToTypeID( "saveStageType" );
      var idsaveSucceeded = stringIDToTypeID( "saveSucceeded" );
      desc9.putEnumerated( idsaveStage, idsaveStageType, idsaveSucceeded );
      executeAction( idsave, desc9, DialogModes.ALL );
      
        • 1. Re: Create folder in last used folder loacation (aka current folder)
          natrev Level 3

          Hi Salvadorr,

           

          Try this code..

          // getting the name and location;    
          var thedoc=app.activeDocument;
          var docName = thedoc.name;    
          if (docName.indexOf(".") != -1) {var basename = docName.match(/(.*)\.[^\.]+$/)[1]}    
          else {var basename = docName};    
          // getting the location, if unsaved save to desktop;    
          try {var docPath = thedoc.path}    
          catch (e) {var docPath = "~/Desktop"};    
          // create folder if it does not exist;    
          var folderString = docPath+"/"+basename;    
          
          var theCopy = thedoc.duplicate(basename,false); 
          OutFoldPSD(folderString+"/Print",basename,true,true,Extension.LOWERCASE);
          theCopy.close(SaveOptions.DONOTSAVECHANGES);
          var theCopy = thedoc.duplicate(basename,false); 
          OutFoldJPEG(folderString+"/Print",basename,12,true,MatteType.NONE,Extension.LOWERCASE);
          theCopy.close(SaveOptions.DONOTSAVECHANGES);
          
          function SaveJPEG(saveFile, jpegQuality,cProfile,MType,fCase){//12,true,MatteType.NONE
              jpgSaveOptions = new JPEGSaveOptions();
              jpgSaveOptions.embedColorProfile = cProfile;
              jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
              jpgSaveOptions.matte = MType; //MatteType.NONE
              jpgSaveOptions.quality = jpegQuality; //1-12
              activeDocument.saveAs(saveFile, jpgSaveOptions, true,fCase);
          }
          
          function OutFoldJPEG(docPath,dnme,jpegQuality,cProfile,MType,fCase){
              var outfolder = new Folder(docPath)
              if (outfolder.exists == false){
                   outfolder.create();
                   var saveFile = new File(outfolder + "/" + dnme);
                  SaveJPEG(saveFile, jpegQuality,cProfile,MType,fCase);}
              else{
                  var saveFile = new File(outfolder + "/" + dnme);
                  SaveJPEG(saveFile, jpegQuality,cProfile,MType,fCase);}
              }
          
          function SavePSD(saveFile,cProfile,alphaCh,fCase){ 
              psdSaveOptions = new PhotoshopSaveOptions(); 
              psdSaveOptions.embedColorProfile = cProfile; //false
              psdSaveOptions.alphaChannels = alphaCh;  //false
              activeDocument.saveAs(saveFile, psdSaveOptions, true, fCase); 
          }    
          
          function OutFoldPSD(docPath,dnme,cProfile,alphaCh,fCase){ 
              var outfolder = new Folder(docPath);
              if (outfolder.exists == false){
                   outfolder.create();
                   var saveFile = new File(outfolder + "/" + dnme);
                  SavePSD(saveFile,cProfile,alphaCh,fCase);}
              else{
                  var saveFile = new File(outfolder + "/" + dnme);
                  SavePSD(saveFile,cProfile,alphaCh,fCase);}
              }