Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Saving multiple TIF without a path

Engaged ,
Apr 18, 2019 Apr 18, 2019

Hello everyone,

I have this script of saving a TIF that i want to improve.

currently it tries to use activeDocument.path, if it doesn't have one it asks to choose the folder via a dialog.

I have 3 documents. document 2 and 3 doesn't have a path because they are new documents (Ctrl+N)

I want if the active document doesn't have a path to loop through all opened documents (start from first document) and then if it finds a path, it exits the loop and uses this path to save all documents that don't have a path.

If none of the documents have a path, it asks to choose the folder where all the documents will be saved at, via a dialog.

this is my original script:

#target photoshop  

    main();  

     

     

    function main(){  

    if(!documents.length) return;  

    var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');  

  

    try{ var savePath = activeDocument.path; } 

    catch(e)

    {  

        savePath = Folder.selectDialog("select folder");

    }  

    var fileList= savePath.getFiles(Name +"*.tif").sort().reverse();  

   

   

   var saveName = File(savePath + "/" + Name) 

    SaveTIFF(saveName);    

    }

   

   

    ////////////////////////////////////////////////////////////////////////////////////////////////// 

    function zeroPad(n, s) {   

       n = n.toString();   

       while (n.length < s)  n = '0' + n;   

       return n;   

    };      

   

    function SaveTIFF(saveFile){ 

tiffSaveOptions = new TiffSaveOptions();  

tiffSaveOptions.embedColorProfile = true;  

tiffSaveOptions.alphaChannels = true;  

tiffSaveOptions.layers = true; 

tiffSaveOptions.imageCompression = TIFFEncoding.NONE; 

//tiffSaveOptions.jpegQuality=10; 

activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);  

Thank you!

TOPICS
Actions and scripting
1.3K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Engaged , Apr 18, 2019 Apr 18, 2019

Thank you!

The code was almost perfect. I wrote something myself before but "continue" was something I missed.

I made a small adjustment to make it work.

When saving, the name of the file is correct and the path is correct like I wanted but it saved only the activeDocument, so all the files are the activeDocument.

so I added a line to make documents the activeDocument and it worked.

BEFORE

HERE IS MY MODIFIED CODE:

#target photoshop

  main();    

        

        

    function main(){    

    for(var

...
Translate
Adobe
Engaged ,
Apr 18, 2019 Apr 18, 2019

   main();    

       

       

    function main(){    

    var  documents=app.documents;

    var Document=app.activeDocument;

    var i=0;

 

    for( i;i<documents.length;i++)

     {

       

           try

           {

               var savePath = documents.path;

               break;

           }   

            catch(e) 

            {    

                if(i==documents.length-1)

                    savePath = Folder.selectDialog("select folder"); 

                else

                continue;

            }    

    }

   

 

    for( i=0;i<documents.length;i++)

     {

           var  Name =documents.name;

           var saveName = File(savePath + "/" + Name)   

            SaveTIFF(saveName);      

      }

   

     

     

    //////////////////////////////////////////////////////////////////////////////////////////////////   

    function zeroPad(n, s) {     

       n = n.toString();     

       while (n.length < s)  n = '0' + n;     

       return n;     

    };        

     

    function SaveTIFF(saveFile){   

tiffSaveOptions = new TiffSaveOptions();    

tiffSaveOptions.embedColorProfile = true;    

tiffSaveOptions.alphaChannels = true;    

tiffSaveOptions.layers = true;   

tiffSaveOptions.imageCompression = TIFFEncoding.NONE;   

//tiffSaveOptions.jpegQuality=10;   

activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);    

}   

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 18, 2019 Apr 18, 2019

Thank you!

The code was almost perfect. I wrote something myself before but "continue" was something I missed.

I made a small adjustment to make it work.

When saving, the name of the file is correct and the path is correct like I wanted but it saved only the activeDocument, so all the files are the activeDocument.

so I added a line to make documents the activeDocument and it worked.

BEFORE

HERE IS MY MODIFIED CODE:

#target photoshop

  main();    

        

        

    function main(){    

    for(var i=0; i< app.documents.length; i++)

  

    {

        

          try

          {

              var savePath = app.documents.path;

              break;

          }    

            catch(e)  

            {    

                if ( i == app.documents.length-1 )

                    savePath = Folder.selectDialog("select folder");  

                else

                continue;

            }    

    }

    

  

    for( i=0; i < app.documents.length ; i++)

    {

          app.activeDocument = app.documents;

          var Name = app.documents.name;

          var saveName = File(savePath + "/" + Name)    

          SaveTIFF(saveName);      

      }

    

}  

      

      

//////////////////////////////////////////////////////////////////////////////////////////////////    

      

      

function SaveTIFF(saveFile){    

tiffSaveOptions = new TiffSaveOptions();    

tiffSaveOptions.embedColorProfile = true;    

tiffSaveOptions.alphaChannels = true;    

tiffSaveOptions.layers = true;    

tiffSaveOptions.imageCompression = TIFFEncoding.NONE;    

//tiffSaveOptions.jpegQuality=10;    

activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);    

}

RESULT :

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Apr 19, 2019 Apr 19, 2019
LATEST

you are right what needing to set activeDocument before saving

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines