Looking for Photoshop Script that gives a file a unique name, saves, and close.

New Here ,
Mar 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

Hello,

I am looking for a Photoshop Script that gives my file a unique name, saves it, then closes it. I am a storyboard artist and I deal with several files and I am looking for a shortcut so that I don't have to manually name all my files. I just want to push a button and then it's named and saved automatically.

 

For example, I'm done drawing a panel, hit a button, then a files saves out as: "Panel_001.PSD" Then I draw another panel, I hit a button, and that panel saves out as "Panel_002.PSD" etc. etc.

 

Thank you.

TOPICS
Actions and scripting

Views

1.5K

Likes

translate

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 1 Correct Answer

Enthusiast , Mar 25, 2020 Mar 25, 2020
  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+$...

Likes

translate

Translate

Translate
Adobe Community Professional ,
Mar 23, 2020 Mar 23, 2020

Copy link to clipboard

Copied

From what it sounds like, you can create an action, but use the File>Automate>Batch command. Be sure to set the Source to Open Files. 

Your action can use any naming convention you want, when you set it up. 

Actions have a "button mode" option, so you can "hit a button"

 

Hope that helps. 

Likes

translate

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
Adobe Community Professional ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

You seem to have forgotten to talk about the location. 

Likes

translate

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
Enthusiast ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

 

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
}

 

* saving only in psd (with default params) to the same folder from which the document was opened, or to the specified folder (if the document has not yet been saved)

Likes

translate

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
Advocate ,
Mar 25, 2020 Mar 25, 2020

Copy link to clipboard

Copied

DmitryEgorov
I find this script very interesting

I would need it for jpg files
you could edit it for me.

Likes

translate

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
Enthusiast ,
Mar 25, 2020 Mar 25, 2020

Copy link to clipboard

Copied

 

 

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
}

 

 

Likes

translate

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
Advocate ,
Mar 25, 2020 Mar 25, 2020

Copy link to clipboard

Copied

Thanks just what I was looking for
it works very well.

Likes

translate

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
New Here ,
Mar 26, 2021 Mar 26, 2021

Copy link to clipboard

Copied

Would you mind editing this script for GIFs, please?

Likes

translate

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
Adobe Community Professional ,
Mar 24, 2020 Mar 24, 2020

Copy link to clipboard

Copied

An alternative approach is to create a new document with the unique filename:

 

https://community.adobe.com/t5/photoshop/vba-to-javascript/m-p/10967341

Likes

translate

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