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

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

Enthusiast ,
Dec 10, 2021 Dec 10, 2021

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();
TOPICS
Actions and scripting , SDK
1.1K
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

Advisor , Dec 16, 2021 Dec 16, 2021

Hello @Mohamed Hameed 

 

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

Screen Shot 2021-12-16 at 11.27.01 PM.png

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.h
...
Translate
Adobe
Community Expert ,
Dec 10, 2021 Dec 10, 2021

@Mohamed Hameed 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.

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
Enthusiast ,
Dec 10, 2021 Dec 10, 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

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
Community Expert ,
Dec 11, 2021 Dec 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 Hameed

 

 

I have absolutely no idea what you want.

 

Perhaps you could type out before and after example filenames.

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
Enthusiast ,
Dec 11, 2021 Dec 11, 2021

@Stephen Marsh 

These two pictures show the before and after
- Before: the files are named automatically according to what was saved by the client, but the files are all one size (100 * 70)

لقطة الشاشة 2021-12-11 154747.png

- After: I want to save all the files so that they become the same name and the same size, but with the addition of white space with each file

لقطة الشاشة 2021-12-11 154856.png

 

- The idea of adding numbers with each file such as 001 - 002 - 003, especially with multiple files, the matter will become complicated when sending the work for printing, because the numbers can be understood as printing numbers

لقطة الشاشة 2021-12-11 155627.png
I hope you understand what I mean

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
Advisor ,
Dec 11, 2021 Dec 11, 2021

Hello @Mohamed Hameed,

 

Give the code below a try for what you're looking for...

// manually save det destination folder


 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],
    // num = i + 1;

tiffFile =  File(Path + "/" +  Mat.text  + "     "+ " " + Math.round(doc.width)+ "       " + Math.round(doc.height)  + ".tif");
  if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" +  Mat.text  + "     "+ " " + Math.round(doc.width)+ "        " + Math.round(doc.height)  + ".tif");
   if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" +  Mat.text  + "     "+ " " + Math.round(doc.width)+ "         " + Math.round(doc.height)  + ".tif");
 if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" +  Mat.text  + "     "+ " " + Math.round(doc.width)+ "          " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" +  Mat.text  + "     "+ " " + Math.round(doc.width)+ "           " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) { 
tiffFile =  File(Path + "/" +  Mat.text  + "     "+ " " + Math.round(doc.width)+ "            " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" +  Mat.text  + "     "+ " " + Math.round(doc.width)+ "             " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" +  Mat.text  + "     "+ " " + Math.round(doc.width)+ "              " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" +  Mat.text  + "     "+ " " + Math.round(doc.width)+ "               " + Math.round(doc.height)  + ".tif");
if (tiffFile.exists === true) {
tiffFile =  File(Path + "/" +  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();

 

Regards,

Mike

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
Enthusiast ,
Dec 11, 2021 Dec 11, 2021

@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

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
Advisor ,
Dec 16, 2021 Dec 16, 2021

Hello @Mohamed Hameed 

 

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

Screen Shot 2021-12-16 at 11.27.01 PM.png

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

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
Enthusiast ,
Dec 17, 2021 Dec 17, 2021
LATEST

mikeb41294032

Thank You Very Much

This code is what is needed.. Thank you

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