Skip to main content
Mohamed Hameed21513110
Inspiring
December 10, 2021
Answered

save all open files to tiff with same name and same size, but add space for every file name

  • December 10, 2021
  • 1 reply
  • 1003 views

I need a code that saves all files opened on Photoshop in TIFF format,

but I work on many files that are similar in terms of name and size and I have a code that saves files in this format, but I want to separate similar files by adding a space in each name so that the file is not saved the other on it

 

- Also, for clarification.. I am working on many files with sizes 100*70 and I want to save them all with one name only by entering the name inside the edittext

 

- This is the code I'm working with, but it's very long and complicated
I want to simplify the code as much as possible

// manually save det destination folder


 dlg = new Window("dialog");   dlg.text = "Enter the Name To Save All File With Same Name"; dlg.preferredSize.width = 200;   dlg.preferredSize.height = 100; 
var Mat = dlg.add ("edittext", [0,0,200,50]); Mat.active=true; 
Size=dlg.add("button", undefined, " OK"  ); Size.alignChildren = ['fill', 'fill'];
 Mat.active=true; 

var Path = Folder.selectDialog("Choose folder to save files to");


Size.onClick = function () { 
 dlg.hide();

        //Get time from getTime function
        var time = getTime();

//HELPER FUNCTIONS
function getTime(){
     var currentTime = new Date();
     var timeOfDay;
     var month = currentTime.getMonth() + 1;
     var day = currentTime.getDate();
     var year = currentTime.getFullYear();
     var hours = currentTime.getHours();
     var minutes = currentTime.getMinutes();
     var Seconds = currentTime.getSeconds();

    //Make timestamp
     //var timeStamp = day + "-" + month + "-" + year + " " + hours + "-" + minutes+ "-" + Seconds ;
     //var timeStamp =  hours + "-" + minutes+ "-" + Seconds ;
     var timeStamp =   minutes+ "-" + Seconds ;
     //var timeStamp = Seconds  ;
     return timeStamp;
}

    for (var i=0; i<app.documents.length; i++) {
    var doc = app.activeDocument = app.documents[i],
    num = i + 1;

tiffFile =  File(Path + "/" + "♥"+ "("+num+")" +"♥"+"   "+  Mat.text  + "     "+ " " + Math.round(doc.width)+ "       " + Math.round(doc.height)  + ".tif");
  if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" + "♥"+ "("+num+")" +"♥"+"   "+  Mat.text  + "     "+ " " + Math.round(doc.width)+ "        " + Math.round(doc.height)  + ".tif");
   if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" + "♥"+ "("+num+")" +"♥"+"   "+  Mat.text  + "     "+ " " + Math.round(doc.width)+ "         " + Math.round(doc.height)  + ".tif");
 if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" + "♥"+ "("+num+")" +"♥"+"   "+  Mat.text  + "     "+ " " + Math.round(doc.width)+ "          " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" + "♥"+ "("+num+")" +"♥"+"   "+  Mat.text  + "     "+ " " + Math.round(doc.width)+ "           " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) { 
tiffFile =  File(Path + "/" + "♥"+ "("+num+")" +"♥"+"   "+  Mat.text  + "     "+ " " + Math.round(doc.width)+ "            " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" + "♥"+ "("+num+")" +"♥"+"   "+  Mat.text  + "     "+ " " + Math.round(doc.width)+ "             " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" + "♥"+ "("+num+")" +"♥"+"   "+  Mat.text  + "     "+ " " + Math.round(doc.width)+ "              " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" + "♥"+ "("+num+")" +"♥"+"   "+  Mat.text  + "     "+ " " + Math.round(doc.width)+ "               " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" + "♥"+ "("+num+")" +"♥"+"   "+  Mat.text  + "     "+ " " + Math.round(doc.width)+ "                " + Math.round(doc.height)  + ".tif");
}
}
}
}
}
}
}
}
}

app.activeDocument.flatten();
app.activeDocument.changeMode(ChangeMode.CMYK);
activeDocument.bitsPerChannel = BitsPerChannelType.EIGHT;
app.preferences.rulerUnits = Units.CM;              app.preferences.typeUnits = TypeUnits.MM;    
var strokeColor = new SolidColor;
	strokeColor.cmyk.cyan = 0;
	strokeColor.cmyk.magenta = 0;
	strokeColor.cmyk.yellow = 0;
	strokeColor.cmyk.black = 100;	
app.activeDocument.selection.selectAll();
app.activeDocument.selection.stroke(strokeColor, 3, StrokeLocation.CENTER);
app.activeDocument.selection.deselect();


tiffSaveOptions = new TiffSaveOptions();   
tiffSaveOptions.embedColorProfile = true;   
//tiffSaveOptions.alphaChannels = true;   
//tiffSaveOptions.layers = true;  
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;  
//tiffSaveOptions.layerCompression=LayerCompression.ZIP;
//tiffSaveOptions.jpegQuality=10;  


activeDocument.saveAs(tiffFile, TiffSaveOptions, true, Extension.LOWERCASE);   


//Restor File To First History record
//app.activeDocument.activeHistoryState = savedState
//Close the current document without saving:
//app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}
while (app.documents.length > 0) {
     
   app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
  
}  
}
dlg.show();
This topic has been closed for replies.
Correct answer Mike Bro

@Mike Bro

First: Thank you
Second: I tested the code on 20 or more files inside Photoshop of the same length and width,

and I noticed that it only saved 15 files.
I want a code that works on any number of files there are


Hello @Mohamed Hameed21513110 

 

Give this a try.......it worked for me on 50+ files!

dlg = new Window("dialog");   dlg.text = "Enter the Name To Save All File With Same Name"; dlg.preferredSize.width = 300; dlg.preferredSize.height = 100; 
var Mat = dlg.add ("edittext", [0,0,200,50]); Mat.active=true; 
Size=dlg.add("button", undefined, " OK"  ); Size.alignChildren = ['fill', 'fill'];
 Mat.active=true; 

var Path = Folder.selectDialog("Choose folder to save files to");

Size.onClick = function () { 
 dlg.hide();

        //Get time from getTime function
        var time = getTime();

//HELPER FUNCTIONS
function getTime(){
     var currentTime = new Date();
     var timeOfDay;
     var month = currentTime.getMonth() + 1;
     var day = currentTime.getDate();
     var year = currentTime.getFullYear();
     var hours = currentTime.getHours();
     var minutes = currentTime.getMinutes();
     var Seconds = currentTime.getSeconds();

    //Make timestamp
     //var timeStamp = day + "-" + month + "-" + year + " " + hours + "-" + minutes+ "-" + Seconds ;
     //var timeStamp =  hours + "-" + minutes+ "-" + Seconds ;
     var timeStamp =   minutes+ "-" + Seconds ;
     //var timeStamp = Seconds  ;
     return timeStamp;
}

    for (var i=0; i<app.documents.length; i++) {
     var doc = app.activeDocument = app.documents[i]; 
      var multi = i+1; var ws = (" "); var mySpace = ""; 
       for(var s = 0; s < multi; s++){
        mySpace += ws

tiffFile =  File(Path + "/" +  Mat.text  + "     "+ " " + Math.round(doc.width)+ "       " + mySpace + Math.round(doc.height)  + ".tif");
}

app.activeDocument.flatten();
app.activeDocument.changeMode(ChangeMode.CMYK);
activeDocument.bitsPerChannel = BitsPerChannelType.EIGHT;
app.preferences.rulerUnits = Units.CM;              app.preferences.typeUnits = TypeUnits.MM;    
var strokeColor = new SolidColor;
	strokeColor.cmyk.cyan = 0;
	strokeColor.cmyk.magenta = 0;
	strokeColor.cmyk.yellow = 0;
	strokeColor.cmyk.black = 100;	
app.activeDocument.selection.selectAll();
app.activeDocument.selection.stroke(strokeColor, 3, StrokeLocation.CENTER);
app.activeDocument.selection.deselect();

tiffSaveOptions = new TiffSaveOptions();   
tiffSaveOptions.embedColorProfile = true;   
//tiffSaveOptions.alphaChannels = true;   
//tiffSaveOptions.layers = true;  
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;  
//tiffSaveOptions.layerCompression=LayerCompression.ZIP;
//tiffSaveOptions.jpegQuality=10;  

activeDocument.saveAs(tiffFile, TiffSaveOptions, true, Extension.LOWERCASE);   

//Restor File To First History record
//app.activeDocument.activeHistoryState = savedState
//Close the current document without saving:
//app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
 }

while (app.documents.length > 0) {
     
   app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
  
  }  
}
dlg.show();

 

Regards,

Mike

1 reply

Stephen Marsh
Community Expert
Community Expert
December 11, 2021

@Mohamed Hameed21513110 wrote:

but I want to separate similar files by adding a space in each name so that the file is not saved the other on it

 

The generally accepted solution to handle duplicate filename clashes is to append one or more zero padded incremental digits, such as 001, 002 etc.

Mohamed Hameed21513110
Inspiring
December 11, 2021

By @Stephen Marsh

The generally accepted solution to handle duplicate filename clashes is to append one or more zero padded incremental digits, such as 001, 002 etc.

Stephen_A_Marsh thanks for your interest
Nice solution how to do this in writing the code

But the problem is that when the files are too many, there will be too many numbers next to the file name
So I want white space so that it is not understood that the added numbers are numbers for the images
These files may be misunderstood when printing

Stephen Marsh
Community Expert
Community Expert
December 11, 2021
quote

So I want white space so that it is not understood that the added numbers are numbers for the images
These files may be misunderstood when printing


By @Mohamed Hameed21513110

 

 

I have absolutely no idea what you want.

 

Perhaps you could type out before and after example filenames.