2 Replies Latest reply on Nov 6, 2017 8:04 AM by JJMack

    looking for a save as Targa script

    dominiquehs Level 1

      Anyone could help me script a SAVE AS .TGA  file in a folder?

      Reason I can't use action is that the tag file needs a new suffix (ex: image_01.tga... image_02.tga... image_03.tga)


      I'm saving dozens of Targas everyday. so please please the one who could help me would be my hero for the rest of the year.


      in short:


      PSD file with layers, ---> save as .tga file with suffix 32 bit.


      Thanks a million!



        • 1. Re: looking for a save as Targa script
          SuperMerlin Level 5

          Please give this a try...


          #target photoshop
          function main(){
          if(!documents.length) return;
          var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
          Name = Name.replace(/\d+$/,'');
          Name = Name.replace(/_$/,'');
          var savePath = activeDocument.path;
              alert("You must save this document first!");
          var fileList= savePath.getFiles(Name +"*.tga").sort().reverse();
          var Suffix = 0;
              Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
          Suffix= zeroPad(Suffix + 1, 3);
          var saveFile = File(savePath + "/" + Name + "_" + Suffix + ".tga");
          function zeroPad(n, s) { 
             n = n.toString(); 
             while (n.length < s)  n = '0' + n; 
             return n; 
          function saveTarga32(saveFile){
          targaSaveOptions = new TargaSaveOptions();
          targaSaveOptions.alphaChannels = true;
          targaSaveOptions.resolution = TargaBitsPerPixels.THIRTYTWO;
          activeDocument.saveAs(File(saveFile), targaSaveOptions, true, Extension.LOWERCASE);
          2 people found this helpful
          • 2. Re: looking for a save as Targa script
            JJMack Most Valuable Participant

            You may want to add  an if to that script.


            if (app.activeDocument.bitsPerChannel==BitsPerChannelType.SIXTEEN) {

              alert("TGA does not support 16 bit color!");