Copy link to clipboard
Copied
I have scanned in a lot of old pictures. Most scans contain up to 5 pictures inside one jpg scanned file.
I made an action that if I highlight a section - I can run the action to have to crop/auto-adjust/etc/then save the file - but as we all know, the action will simply overwrite the same file name if it's in the action. I toggled the dialog for that step but I'm ready for a script that saves the same file name with an appending sequential number or letter.
Scan001.jpg turns into
Scan001-a.jpg
Scan001-b.jpg
Scan001-c.jpg
Scan001-d.jpg
Scan001-e.jpg
OR
Scan001-1.jpg
Scan001-2.jpg
Scan001-3.jpg
Scan001-4.jpg
Scan001-5.jpg
Something like that automatically by me simply highlighting and running my action again. Anyone have a script for something like that? Or another method to automate this madness? It started as a small scanning project and now I have hundreds of scans...
An action can not do that you need to use Photoshop scripting use logic to generate the file names you want to save.
Sadly most of these are either broken links due to adobe's changes over the years. I was able to piece together some code that seems to work, but pretty tedious. I can't imagine I'm the only one desiring this as a mainstream option in a product that's been out for decades. But thank you for your help.
main();
function main()
{
try {
var path = "C:/MyPath"; // path where to save
var name = activeDocument.name;
var n = name.lastIndexOf(".");
if (n > 0) name = name.substr(0, n);
var idx = 1;
do
{
var file = new File(path + "/" + name + "-" + idx + ".jpg");
++idx;
Here are some of the scripts from those "broken" links:
/*
automate save as or export with sequential file names
https://community.adobe.com/t5/photoshop/automate-save-as-or-export-with-sequential-file-names/td-p/9003836
2020 - Original script modified to remove the original filename from the sequential output file
https://forums.adobe.com/message/4453915#4453915
*/
#target photoshop
main();
function main() {
if (!documents.length) return;
var Name = app.activeDocument.name.replace
...
Copy link to clipboard
Copied
@Erik5E80 wrote:
save the file - but as we all know, the action will simply overwrite the same file name if it's in the action.
Copy link to clipboard
Copied
I WANT to change the filename. I want the action to use the original name but append a number after it as I crop and save each area of the picture. So if the filename exists already, increment the number.
Copy link to clipboard
Copied
An action can not do that you need to use Photoshop scripting use logic to generate the file names you want to save.
Copy link to clipboard
Copied
Weather you duplicate the current document, you get documents with the ending in the name: copy, copy 2, copy 3, etc. Doesn't this suit you?
Copy link to clipboard
Copied
Perhaps saving into JPEG after cropping out the various sections from the large scan is not so great, as I assume that you then come back later, open and edit them and resave again?
There are many sequential save scripts on the forum:
Or just search the forum for "sequential" or "incremental" etc.
Copy link to clipboard
Copied
Removing from end of links #M{5 digits} give better view of top post (so with its title) 😉
Copy link to clipboard
Copied
Sadly most of these are either broken links due to adobe's changes over the years. I was able to piece together some code that seems to work, but pretty tedious. I can't imagine I'm the only one desiring this as a mainstream option in a product that's been out for decades. But thank you for your help.
Copy link to clipboard
Copied
Here are some of the scripts from those "broken" links:
/*
automate save as or export with sequential file names
https://community.adobe.com/t5/photoshop/automate-save-as-or-export-with-sequential-file-names/td-p/9003836
2020 - Original script modified to remove the original filename from the sequential output file
https://forums.adobe.com/message/4453915#4453915
*/
#target photoshop
main();
function main() {
if (!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
try {
var savePath = activeDocument.path;
} catch (e) {
alert("You must save this document first!");
}
var fileList = savePath.getFiles("*.jpg").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 + ".jpg");
var saveFile = File(savePath + "/" + Suffix + ".jpg");
SaveJPEG(saveFile, 8); // JPEG compression level
}
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);
}
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
}
#target photoshop
main();
function main() {
if (!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
Name = Name.replace(/\d+$/, '');
layerName = app.activeDocument.activeLayer.name.replace(/\.[^\.]+$/, '');
combinedName = Name + "_" + layerName;
try {
var savePath = activeDocument.path;
} catch (e) {
alert("You must save this document first!");
}
var fileList = savePath.getFiles(combinedName + "*.psd").sort().reverse();
var Suffix = 0;
if (fileList.length) {
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix = zeroPad(Suffix + 1, 4);
var saveFile = File(savePath + "/" + combinedName + "_" + Suffix + ".psd");
SavePSD(saveFile);
}
function SavePSD(saveFile) {
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
}
#target photoshop
main();
function main() {
if (!documents.length) return;
var Name = app.activeDocument.activeLayer.name.replace(/\.[^\.]+$/, '');
try {
var savePath = activeDocument.path;
} catch (e) {
alert("You must save this document first!");
}
var fileList = savePath.getFiles(Name + "*.psd").sort().reverse();
var Suffix = 0;
if (fileList.length) {
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix = zeroPad(Suffix + 1, 4);
var saveFile = File(savePath + "/" + Name + "_" + Suffix + ".psd");
SavePSD(saveFile);
}
function SavePSD(saveFile) {
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
}
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
}
#target photoshop
main();
function main(){
if(!documents.length) return;
var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');
Name = Name.replace(/\d+$/,'');
try{
var savePath = activeDocument.path;
}catch(e){
alert("You must save this document first!");
}
var fileList= savePath.getFiles(Name +"*.psd").sort().reverse();
var Suffix = 0;
if(fileList.length){
Suffix = Number(fileList[0].name.replace(/\.[^\.]+$/, '').match(/\d+$/));
}
Suffix= zeroPad(Suffix + 1, 4);
var saveFile = File(savePath + "/" + Name + "_" + Suffix + ".psd");
SavePSD(saveFile);
}
function SavePSD(saveFile){
psdSaveOptions = new PhotoshopSaveOptions();
psdSaveOptions.embedColorProfile = true;
psdSaveOptions.alphaChannels = true;
psdSaveOptions.layers = true;
activeDocument.saveAs(saveFile, psdSaveOptions, true, Extension.LOWERCASE);
};
function zeroPad(n, s) {
n = n.toString();
while (n.length < s) n = '0' + n;
return n;
};
if (app.documents.length) {
try { var f = app.activeDocument.fullName } catch (e) {
var p = new Folder; f = p.selectDlg(); if (f) f = File(f + '/' + app.activeDocument.name)
}
if (f) {
activeDocument.saveAs(createUniqueFileName(f))
activeDocument.close()
}
}
function createUniqueFileName(f) {
var inPath = decodeURI(f.parent),
inFile = decodeURI(f.name).replace(/\.[^\.]+$/, '').replace(/_\d+$/,''),
inExt = '.psd',
uniqueFileName = File(inPath + '/' + inFile + inExt),
fileNumber = 1
while (uniqueFileName.exists) {
uniqueFileName = File(inPath + '/' + inFile + "_" + ('000' + fileNumber).slice(-3) + inExt)
fileNumber++;
}
return uniqueFileName
}
if (app.documents.length) {
try { var f = app.activeDocument.fullName } catch (e) {
var p = new Folder; f = p.selectDlg(); if (f) f = File(f + '/' + app.activeDocument.name)
}
if (f) {
(o = new JPEGSaveOptions ()).quality = 12
activeDocument.saveAs(createUniqueFileName(f), o)
activeDocument.close()
}
}
function createUniqueFileName(f) {
var inPath = decodeURI(f.parent),
inFile = decodeURI(f.name).replace(/\.[^\.]+$/, '').replace(/_\d+$/,''),
inExt = '.jpg',
uniqueFileName = File(inPath + '/' + inFile + inExt),
fileNumber = 1
while (uniqueFileName.exists) {
uniqueFileName = File(inPath + '/' + inFile + "_" + ('000' + fileNumber).slice(-3) + inExt)
fileNumber++;
}
return uniqueFileName
}
try {
while (1)
{
var _file = new File("C:\\Users\\KoolKATZDesigns\\Desktop\\Script Tests\\Names.txt");
var number = 0;
if (_file.exists)
{
_file.open("r");
number = Number(_file.read());
if (_file.error) { alert("Params read error!", "Error", true); _file.close(); break; }
_file.close();
}
++number;
_file.open("w");
_file.write(number);
if (_file.error) { alert("Params save error!", "Error", true); _file.close(); break; }
_file.close();
var _name = "DOC_" + number;
app.documents.add(UnitValue(1920, "px"), UnitValue(1080, "px"), 72, _name, NewDocumentMode.RGB, DocumentFill.WHITE, 1, BitsPerChannelType.EIGHT, "sRGB IEC61966-2.1");
break;
}
}
catch (e) { alert(e); }
Copy link to clipboard
Copied
If you can't achieve exactly what you want in Photoshop, Adobe Bridge has a fantastic batch renaming process.
Change multiple file names with Batch Rename in Bridge
https://youtu.be/N7iIPcoGfjg
Copy link to clipboard
Copied
main();
function main()
{
try {
var path = "C:/MyPath"; // path where to save
var name = activeDocument.name;
var n = name.lastIndexOf(".");
if (n > 0) name = name.substr(0, n);
var idx = 1;
do
{
var file = new File(path + "/" + name + "-" + idx + ".jpg");
++idx;
}
while (file.exists)
var d = new ActionDescriptor();
var d1 = new ActionDescriptor();
d1.putInteger(stringIDToTypeID("extendedQuality"), 12); // jpeg quality here
d1.putBoolean(stringIDToTypeID("optimized"), false);
d1.putEnumerated(stringIDToTypeID("matteColor"), stringIDToTypeID("matteColor"), stringIDToTypeID("none"));
d.putObject(stringIDToTypeID("as"), stringIDToTypeID("JPEG"), d1);
d.putPath(stringIDToTypeID("in"), file);
d.putBoolean(stringIDToTypeID("copy"), true);
d.putBoolean(stringIDToTypeID("embedProfiles"), true);
executeAction(stringIDToTypeID("save"), d, DialogModes.NO);
}
catch (e)
{
alert(e);
}
}