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

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

2.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 1 Correct answer

Guide , 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+$
...

Votes

Translate

Translate
Adobe
Community Expert ,
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. 


Adobe Community Expert / Adobe Certified Instructor

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

Copy link to clipboard

Copied

You seem to have forgotten to talk about the location. 

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
Guide ,
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)

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

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
Guide ,
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
}

 

 

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

Copy link to clipboard

Copied

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

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

Copy link to clipboard

Copied

LATEST

Would you mind editing this script for GIFs, please?

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

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