Skip to main content
Participating Frequently
June 3, 2010
Question

Rename file as part of Bridge script

  • June 3, 2010
  • 1 reply
  • 2204 views

Hello. I have a simple script that I would like to modify to rename the images sequentially as they are processed. If anyone can give me a hint how to rewrite

var saveFile = new File(docPath+'/'+targetName+'.jpg');

to

var saveFile = new File(docPath+'/'+'MyStaticText' + Two Digit Serial Number +'.jpg');

I would really appreciate the help. Here is the full original script:

///#target photoshop


/// Save for Webshow

/// Set JPGquailty. Can be 1 - 12.
var JPGquality = 8;
/////////////////////////////////////////////////////////////////////////

if(documents.length){
var docPath='';
var docName='';
var parentName='';
var grandName='';

try{
   docName = activeDocument.name;
   docPath = activeDocument.path.parent + "/WebshowUpload/images";  
   var arrayPath = activeDocument.path.toString().split('/'); 
   if (arrayPath.length > 2)
   {
        parentName = arrayPath[arrayPath.length-1];
        grandName = arrayPath[arrayPath.length-2];
   }
}

catch(e){

      docPath = new Folder("~/desktop");
      docName = activeDocument.name + '.jpg';
      }

var docNAME = docName.split('.');
var targetName = docNAME[0];
var saveFile = new File(docPath+'/'+targetName+'.jpg');
SaveJPEG(saveFile, JPGquality)

}

// Save Webshow Thumbnail

doAction("01_ResizeThumbnail","Wedding_ConvertForWebshow");

/// Set JPGquailty. Can be 1 - 12.
var JPGquality = 8;
/////////////////////////////////////////////////////////////////////////

if(documents.length){
var docPath='';
var docName='';
var parentName='';
var grandName='';

try{
   docName = activeDocument.name;
   docPath = activeDocument.path.parent + "/WebshowUpload/tn";  
   var arrayPath = activeDocument.path.toString().split('/'); 
   if (arrayPath.length > 2)
   {
        parentName = arrayPath[arrayPath.length-1];
        grandName = arrayPath[arrayPath.length-2];
   }
}

catch(e){

      docPath = new Folder("~/desktop");
      docName = activeDocument.name + '.jpg';
      }

var docNAME = docName.split('.');
var targetName = docNAME[0];
var saveFile = new File(docPath+'/'+targetName+'.jpg');
SaveJPEG(saveFile, JPGquality)
}

activeDocument.close(SaveOptions.DONOTSAVECHANGES);

//FUNCTIONS
////////////////////////////////////////////////////////////////////////////////////

function SaveJPEG(saveFile, jpegQuality){

jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality; //1-12
activeDocument.saveAs(saveFile, jpgSaveOptions, true, Extension.LOWERCASE);

}

In other words, the resulting images should be MyStaticText01.jpg, MyStaticText02.jpg, MyStaticText03.jpg, etc. Thanks.

This topic has been closed for replies.

1 reply

Paul Riggott
Inspiring
June 3, 2010

This is a Photoshop script not a Bridge script.

The script itself is written to process only the active document and could be modified BUT would only process the documents that are open in Photoshop.

Maybe this script will do more of what you want..?

http://www.ps-scripts.com/bb/viewtopic.php?f=10&t=3383&sid=ec250091935a0e4768a31c63033b0b04

Participating Frequently
June 3, 2010

Paul,

Thank you for your response. My apologies if I posted this in the wrong forum; I run this script from Bridge on a selection of images.

My intent is to use this same script as it resizes images and saves them into subfolders. I would just like to update the script so that it also renames the images at the time of saving so that they follow a specific naming convention, ie MyStaticText01.jpg, MyStaticText02.jpg, etc. This allows me to use the resulting images in a Flash slideshow without having to redo the slideshow everytime with the different original image names which vary from project to project. I just don't know how to create incremental file names with this script or if it is possible.

If a true Bridge script is required to accomplish this task, then I would be interested in that.

I attempted to install your "Process Selected Bridge Files" on CS4 on a Mac, but get repeated errors "Sorry but this script needs CS3 or better" so I have not been able to evaluate it for my needs. Bummer.

Thanks for any input.

Eric

Paul Riggott
Inspiring
June 3, 2010

The problem you have is that this script is probably been called by an action, which makes this script not suitable for adding a sequence number. To add a sequence number you need a batch processor of some description or even more difficult check the destination folder for all filenames and work out what the next sequence number should be, not a simple task.