• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Saving sequential file names of the same file to multiple files?

Community Beginner ,
May 08, 2021 May 08, 2021

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... 

TOPICS
Actions and scripting

Views

5.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 4 Correct answers

Community Expert , May 08, 2021 May 08, 2021

An action can not do that you need to use Photoshop scripting use logic to generate the file names you want to save.

Votes

Translate

Translate
Community Beginner , May 09, 2021 May 09, 2021

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.

Votes

Translate

Translate
People's Champ , May 09, 2021 May 09, 2021
Try replacing the saveAs command in action with a call to this script. Set the path and quality of the jpg in the script yourself.
...

Votes

Translate

Translate
Community Expert , May 10, 2021 May 10, 2021

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
...

Votes

Translate

Translate
Adobe
People's Champ ,
May 08, 2021 May 08, 2021

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.   



If the action is recorded without changing the file name, then it will not change the file name. This action will save any of your files with its original name.
zzz.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 08, 2021 May 08, 2021

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.  

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2021 May 08, 2021

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.

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 08, 2021 May 08, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2021 May 08, 2021

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 09, 2021 May 09, 2021

Copy link to clipboard

Copied

Removing from end of links #M{5 digits} give better view of top post (so with its title) 😉

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
May 09, 2021 May 09, 2021

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 10, 2021 May 10, 2021

Copy link to clipboard

Copied

LATEST

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); }

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 08, 2021 May 08, 2021

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

Renaming multiple files can be an extremely tedious task. Bridge can dramatically simplify and automate this process. Details below... Patreon: https://www.patreon.com/MichaelBullo Renaming methods include appending text, number sequences, incorporating Metadata and complex string substitutions ...

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
May 09, 2021 May 09, 2021

Copy link to clipboard

Copied

Try replacing the saveAs command in action with a call to this script. Set the path and quality of the jpg in the script yourself.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines