Copy link to clipboard
Copied
Hey guys
Can anyone help me create a script that will do the following ( i thing its pretty simple but can't program >< )
Active document save as TIFF and rename to 'Bamboo', - if file name exists, save as 'Bamboo_1', and a counter for more and more if Bamboo1' exists, create Bamboo_2 etc ...
Not saving as batch but i need fast production saving the files to be efficient in my production as we send the files to a priner. At the moment, we rename manually which is super hard to keep track on.
I also have a template name "2sides" and we use the same template for different photos throughout the day, would love to have a script that renames the file in case its exists. Couldn't find a way to do with the action as it keeps overwriting the file.
Will really appreciate any help !
Thanks
Tom
Copy link to clipboard
Copied
A simple modification to some old code did the job, let me know how it goes!
// https://forums.adobe.com/message/4453915#4453915
#target photoshop
main();
function main() {
if (!documents.length) return;
// var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
var Name = "Bamboo"
try {
var savePath = activeDocument.path;
} catch (e) {
alert("You must save this document first!");
}
var fileList = savePath.getFiles(Name + "*.tif").sort().reverse();
var Suffix = 0;
if (fileList.length) {
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix = zeroPad(Suffix + 1, 3);
var saveFile = File(savePath + "/" + Name + "_" + Suffix + ".tif");
SaveTIFF(saveFile);
}
function SaveTIFF(saveFile) {
// http://jongware.mit.edu/pscs5js_html/psjscs5/pc_TiffSaveOptions.html
// http://jongware.mit.edu/pscs5js_html/psjscs5/pe_TIFFEncoding.html
// TIFFEncoding.NONE
// TIFFEncoding.JPEG
// TIFFEncoding.TIFFLZW
// TIFFEncoding.TIFFZIP
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.byteOrder = ByteOrder.IBM;
tiffSaveOptions.transparency = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.layerCompression = LayerCompression.ZIP;
tiffSaveOptions.interleaveChannels = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.spotColors = true;
tiffSaveOptions.imageCompression = TIFFEncoding.TIFFLZW;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
}
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
}
Copy link to clipboard
Copied
Brilliant mate that works fantastic !! Thank you so much !
Quick question, How can I add a condition there say "if var name = "Hexagon" ... ' run script
Else, just save file with its name?
Copy link to clipboard
Copied
I got the hang of it and managed to tweak it the way I want so thanks for that.
Im just not sure how I can make it to save the file with its activeDocument.name if there is no file under the same name so it'll just execute a regular save, i tried to not use the try and catch but that didn't work.
So what happens is its saves the file twice;. Once with currentDocument.name ( and keep replacing the same file every time F2 is applied ) and then with the suffix progressing...
I guess its because the action is a save + script .
So i just took
var Name = app.activeDocument.name
Any advice of what the most efficient way of doing it? Basically its just consuming a lot of computing power. especially because the template i use is around 200 mb every time. Imagine i process 5 of these, not very efficeint.
Copy link to clipboard
Copied
If the Active document is a new document that has never been saved a script would not know where to save the active document unless you program some logic in the script to find a logical place to save the document. Its easy for a script to see if the document has a backing files and save the next version it the same folder. When there is no backing file the script need to have a way to fine where you want the document saved there is no magic only illusions. I'm sure the Image Processors will inform you the Document need to be saved if you did not set a destination folder. Only New unsaved document do not have a file on disk. The Root file need to exist if you want to add a suffix. I would also think you would use layered file like PSD, Tiff and PSB. You could open a layered document and save out flat Jpeg, png, tiff etc, You would still need to save a layered document not to loose you work layers.
Copy link to clipboard
Copied
Yea that make sense i guess. But then what happes is when the action is executed the file is being saved twice. 1 with the regular action save and rename ( hardcode name change ) and then 1 time via the script.
What u reckon the best way to avoid that?
Copy link to clipboard
Copied
If you want to save versions the Action should use the script to do the save and there should not be two save in the script. So if you open a new document and immediately do a save as you have save the original empty with a file name without a version suffix is some folder. If you do not save the original and use the script to do the save the script can see that there is no original and have some logic to find out where you want the document saved. The Script for example could put you in a select folder dialog for you to select the destination folder. Once you select the folder the script would save the original with the document name without a version suffix. Its not that complex. However, if you want to use the Image Processor Pro... in an action so you can have the Save on a key press the original must be save first you. It you do not and use the key press you will get that message from Image Processor Pto as follows.
Copy link to clipboard
Copied
That is how the Image Processor Script works. It can process as single image as well as a batch of images. If the Output image exists it will create a new file and add a suffix to the file name. Here is the Function it uses when saving files to save only new file. It generates the file names you want. It starts with _1. Adobe install the script you want. menu File>Scripts>Image Processor... .
///////////////////////////////////////////////////////////////////////////////
// Function: CreateUniqueFileName
// Usage: Given a folder, filename, and extension, come up with a unique file name
// using a numbering system
// Input: string for folder, fileName, and extension, extension contains the "."
// Return: string for the full path to the unique file
///////////////////////////////////////////////////////////////////////////////
function CreateUniqueFileName( inFolder, inFileName, inExtension ) {
inFileName = inFileName.replace(/[:\/\\*\?\"\<\>\|]/g, "_"); // '/\:*?"<>|' -> '_'
var uniqueFileName = inFolder + inFileName + inExtension;
var fileNumber = 1;
while ( File( uniqueFileName ).exists ) {
uniqueFileName = inFolder + inFileName + "_" + fileNumber + inExtension;
fileNumber++;
}
return uniqueFileName;
}
There is a better script on the web Image Processor Pro... which is a Plug-in script so you can record your setting in an Action step and not have to use its dialog to save your tiff files, You could set as shortcut for the Action and save your files via a key press like F2. However, you will most likely need to use an Old version of Photoshop to record the Action. The Action recorder in current version of Photoshop seems to have a problem recording Image Processor Pro.. Action step. Even in old version of Photoshop where Photoshop recorded a step that works correctly the step in The action palette the action's Image Processor Pro... step looks like an empty step that Image Processor Pro... is not part of the action. Here is an Action I just recorded in CS6. I Loaded that Action into PS 21.2 seen here. I opened a PSD file in a testfoldet and press the F2 key a few times. You can see after after the first TIFF file that a suffix was added startint with _01,
Copy link to clipboard
Copied
Thanks JJ, Just couldn't really figure out how to do it for 1 file if say i have 10 active documents, "current" , also, it does require another step of pressing "Run" after the action so its not quiet what I was looking for.
Stephen code's works perfect for that 🙂
Copy link to clipboard
Copied
Not if you record an image processor Prro step in an action then all that is required is a single key press, no dialog is even displayed.
Copy link to clipboard
Copied
Sounds like it worth a shot. I'll play around with it see how it goes. Thanks for your help ! U reckon the photoshop 2020 will have issues with that?
Copy link to clipboard
Copied
With the Image Processor Pro,,, you can record a generic save as step to save the same type of file you opened as shown below. Or record a particular support type. You cane even save one of each type BMP, GIF, JPEG, PSD, ESP PDF, PNG, Targa and TIFF with a single key press
Copy link to clipboard
Copied
Got it JJ,
Processor Pro works fine !
Hopefully it'll stay table and wont have any glithces.
Thanks a lot for your help !!