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

Script can rename current document

Explorer ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

Hello everyone,

I need script can rename the current document opening to what I need then save not save as, while run script open dialogue box to write name then ok rename but not open in new tab rename in the same document.

TOPICS
Actions and scripting

Views

865

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

Community Expert , Feb 04, 2021 Feb 04, 2021
ahmada96002504 wrote:
How?

 

Something like this:

 

 

#target photoshop
    (function () {
        if (app.documents.length > 0) {
            var origDoc = app.activeDocument;
            var origDocName = origDoc.name.replace(/\.[^\.]+$/, '');
            var newDocName = prompt("Enter New Filename:", origDocName);
            if (newDocName === null) {
                alert('Script cancelled!');
                return;
            }
            origDoc.duplicate((newDocName), false);
        
...

Votes

Translate

Translate
Adobe
Community Expert ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

No.

 

You may see the current document name changes when you use save as  to save a new document for the first time.  activeDocument.name is read only.

image.png

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
Explorer ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

How i can get in script code?

I don't have knoqledge about script coding

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 ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

You can't rename an open file. Either Save As or close it, rename, then re-open it.

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 ,
Feb 03, 2021 Feb 03, 2021

Copy link to clipboard

Copied

The only other option not yet mentioned is to script a duplicate the doc and rename then close the original without saving. This would result in another file when saving. This is why renaming before opening was recommended.

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
Explorer ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

How?

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 ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

It will depend on the required file name, which you have not yet mentioned. Is it based on the original variable document name with a static prefix or suffix? Is it based on some file property or metadata property? Or will a promo be used so that you can type in the new name manually?

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 ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

ahmada96002504 wrote:
How?

 

Something like this:

 

 

#target photoshop
    (function () {
        if (app.documents.length > 0) {
            var origDoc = app.activeDocument;
            var origDocName = origDoc.name.replace(/\.[^\.]+$/, '');
            var newDocName = prompt("Enter New Filename:", origDocName);
            if (newDocName === null) {
                alert('Script cancelled!');
                return;
            }
            origDoc.duplicate((newDocName), false);
            origDoc.close(SaveOptions.DONOTSAVECHANGES);
        } else {
            alert('A document must be open to use this script!');
        }
    })
    ();

 

 

 

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
Explorer ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

LATEST

It work thanks,

It works fine.

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 ,
Feb 04, 2021 Feb 04, 2021

Copy link to clipboard

Copied

You can duplicate the document with the name you want in Photoshop close the originals document and delete its backing file if one exists. The only place it exist then is in Photoshop with the document name you want. You should then save it to disk so there is a file containing the data.

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