Skip to main content
Participating Frequently
July 13, 2020
Question

Script Help

  • July 13, 2020
  • 3 replies
  • 1710 views

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

This topic has been closed for replies.

3 replies

JJMack
Community Expert
Community Expert
July 13, 2020

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

 

JJMack
tomerperAuthor
Participating Frequently
July 14, 2020

Got it JJ, 

Processor Pro works fine ! 

Hopefully it'll stay table and wont have any glithces.

 

Thanks a lot for your help !! 

JJMack
Community Expert
Community Expert
July 13, 2020

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,

JJMack
tomerperAuthor
Participating Frequently
July 13, 2020

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 🙂 

JJMack
Community Expert
Community Expert
July 13, 2020

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.

JJMack
Stephen Marsh
Community Expert
Community Expert
July 13, 2020

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;
}
tomerperAuthor
Participating Frequently
July 13, 2020

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?