Copy link to clipboard
Copied
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();
Hello @Mohamed Hameed
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.h...
Copy link to clipboard
Copied
@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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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)
- 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
- 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
I hope you understand what I mean
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hello @Mohamed Hameed
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
Copy link to clipboard
Copied
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more