I have this script: I select a folder, open only tif and psd in it (subfolders included), then if a file contains a substring in it, it changes the name (removes the substring), then it saves as tif with the new name, saves as jpg 5 with the new name, then deletes the original file.
#target photoshop
// Select folder dialog, open only tif and psd, if contains the substring: change the name: save tif, save jpg 5, then delete the file.
var theFolder = Folder.selectDialog("select folder");
var fileandfolderAr = scanSubFolders(theFolder,/\.(tif|psd)$/i); //var fileandfolderAr = scanSubFolders(topFolder,/\.(jpg|tif|psd|bmp|gif|png|)$/i);
var fileList = fileandfolderAr[0];
var substring = "-temp";
for (var a = 0 ;a < fileList.length; a++)
{
var Name = fileList.name;
if (Name.match(substring))
{
Name = Name.replace(substring,'');
var savePath = fileList.path;
var saveName = File(savePath + "/" + Name)
SaveTIFF(saveName);
SaveJPEG(saveName,5);
fileList.remove();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
function scanSubFolders(tFolder, mask) { // folder object, RegExp or string
var sFolders = new Array();
var allFiles = new Array();
sFolders[0] = tFolder;
for (var j = 0; j < sFolders.length; j++){ // loop through folders
var procFiles = sFolders.getFiles();
for (var i=0;i<procFiles.length;i++){ // loop through this folder contents
if (procFiles instanceof File ){
if(mask==undefined) allFiles.push(procFiles);// if no search mask collect all files
if (procFiles.fullName.search(mask) != -1) allFiles.push(procFiles); // otherwise only those that match mask
}else if (procFiles instanceof Folder){
sFolders.push(procFiles);// store the subfolder
scanSubFolders(procFiles, mask);// search the subfolder
}
}
}
return [allFiles,sFolders];
};
function SaveTIFF(saveFile){
tiffSaveOptions = new TiffSaveOptions();
tiffSaveOptions.embedColorProfile = true;
tiffSaveOptions.alphaChannels = true;
tiffSaveOptions.layers = true;
tiffSaveOptions.imageCompression = TIFFEncoding.NONE;
activeDocument.saveAs(saveFile, tiffSaveOptions, true, Extension.LOWERCASE);
}
function SaveJPEG(saveFile, jpegQuality){
jpgSaveOptions = new JPEGSaveOptions();
jpgSaveOptions.embedColorProfile = true;
jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE;
jpgSaveOptions.matte = MatteType.NONE;
jpgSaveOptions.quality = jpegQuality;
activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE);
};