5 Replies Latest reply on Jan 12, 2016 3:55 PM by Whatevermajorloser

    save a file based on computer name

    brianflieck

      i'm looking to save a file based on a users name or document on their computer.

       

      i have several users that use the same actions but the destinations chnage based on the user.

       

      /Volumes/photorepos/Partners/PostDrop/username

       

      can i have the script check the computer name and then make sure that computer name matches the username of the folder so that when the user hits the action it goes right to that destination?

        • 1. Re: save a file based on computer name
          Whatevermajorloser

          Hi brianflieck,

           

          Use the following to find out the user's name:

           

          $.writeln($.getenv('USER')); 
          
          
          
          
          
          
          

           

          This will write the user's name to the console in ExtendScript Toolkit

           

          So if the destination folder changes based on their username, you could implement it like this:

           

          var userName = $.getenv("USER")
          var saveFile = new File('/Volumes/photorepos/Partners/PostDrop/' + userName + '/' + activeDocument.name)
          activeDocument.saveAs(saveFile, undefined, false, Extension.LOWERCASE)
          
          
          
          
          
          
          

           

          Hope this helps!

          • 2. Re: save a file based on computer name
            brianflieck Level 1

            it seems to stop on line 2?

             

            var userName = $.getenv("USER")  
            var saveFile = new File('/Volumes/photorepos/Partners/PostDrop/' + userName + '/' + activeDocument.name)  
            activeDocument.saveAs(saveFile, undefined, false, Extension.LOWERCASE)  
            
            

            should it have just worked with this basic code?

             

            thanks!

            • 3. Re: save a file based on computer name
              Whatevermajorloser Level 1

              It should work, unless the name of the folder doesn't match the actual username of the person running it. What does it say when it stops?

               

              You could check this by checking if the folder exists in an if/else statement:

               

              var userName = $.getenv("USER")
              var folderLocation = '/Volumes/photorepos/Partners/PostDrop/'
              
              if(Folder(folderLocation + userName).exists){
                var saveFile = new File(folderLocation + userName + '/' + activeDocument.name)
                activeDocument.saveAs(saveFile, undefined, false, Extension.LOWERCASE)
              } else {
                alert("Folder not found!\nEither it doesn't exist or its name doesn't match that of the user.")
              }
              
              
              
              
              
              • 4. Re: save a file based on computer name
                brianflieck Level 1

                it worked! is there a way to make it so it saves a LZW sRGB TIFF? it's saving as a PSD right now

                • 5. Re: save a file based on computer name
                  Whatevermajorloser Level 1

                  Sorry for the late response. If you want to save as a tiff, you'll have to specify some tiff save options (Line 4 - 7) and include them as one of the parameters of the saveAs method on the activeDocument object (Line 11). The final code should look something like this:

                   

                  var userName = $.getenv("USER")
                  var folderLocation = '/Volumes/photorepos/Partners/PostDrop/'
                  
                  var tifSaveOptions = new TiffSaveOptions();
                  tifSaveOptions.embedColorProfile = true;
                  tifSaveOptions.layers = true;
                  tifSaveOptions.imageCompression = TIFFEncoding.TIFFLZW
                  
                  if(Folder(folderLocation + userName).exists){
                    var saveFile = new File(folderLocation + userName + '/' + activeDocument.name)
                    activeDocument.saveAs(saveFile, tifSaveOptions, false, Extension.LOWERCASE)
                  } else {
                    alert("Folder not found!\nEither it doesn't exist or its name doesn't match that of the user.")
                  }
                  
                  

                   

                  I recommend you read the Photoshop CC JavaScript Reference Guide for help with Photoshop scripting. Details about tiff save options can be found on page 213. Also, see here for further documentation on Photoshop scripting: Adobe Photoshop Scripting | Adobe Developer Connection.