Stop photoshop adding number suffixes to documents

Community Beginner ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Normally when opening a file in Photoshop, the document has the same name as the file, and saves as the same name.

For example, if I open "test.PSD" or "test.DNG" or "test.PNG", or whatever, do some edits, then export for web, I get "test.jpg".

However, when opening a RAW file as a smart object (via Adobe Camera RAW), the resulting document has a number appended to it - "<raw filename minus extension>-1"

For example, if I open "test.DNG" as a smart object, I get a document called "test-1", which will save as "test-1.jpg"

Unfortunately my workflow relies on the document having the same name as the file it came from, and this breaks everything.

Does anyone know how to either:

  1. Automate the process of exporting/renaming the file such that it strips off these extra added numbers in some reliable way, or
  2. Stops Photoshop adding the extra numbers to document title in the first place, when opening files as smart objects?

Thanks 🙂

TOPICS
Actions and scripting

Views

129

Likes

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

Adobe Community Professional , Feb 22, 2022 Feb 22, 2022
@nedmartin  Here is a v2 code that will loop over all open docs. I have tested this with multiple files opened from ACR as smart objects with the new script being triggered by the Script Event Manager. Please let me know how it goes for you... /* Remove Ending Hyphen Digit from ACR Smart Object Files v2.jsx https://community.adobe.com/t5/photoshop-ecosystem-discussions/stop-photoshop-adding-number-suffixes-to-documents/m-p/12767371 Stephen Marsh, 23rd February 2022, v2.0 Note: Use the scri...

Likes

Translate

Translate
Adobe Community Professional ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

I'm thinking that a simple script to duplicate the current file removing the -# digit character and close down the original file (conditions that the file must have a -\d+$ and that the active layer is a smart object (possibly further checks to see if the image was processed by ACR through metadata etc).

 

This would be automated via the Scripts Events Manager for opened files (if such files passed by ACR are triggered by the open event).

Likes

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 ,
Feb 21, 2022 Feb 21, 2022

Copy link to clipboard

Copied

Here is the basic script, which does indeed work with the open event in Script Events Manager:

 

/*
Remove Ending Hyphen Digit from ACR Smart Object Files.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/stop-photoshop-adding-number-suffixes-to-documents/m-p/12767371
Stephen Marsh, 22nd February 2022, v1.0
Note: Use the scripts events manager open event to run this script
*/

try {
    // Previously saved doc
    if (activeDocument.path) {}
} catch (e) {
    // Unsaved doc
    if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
    var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
    var crsMeta = xmp.getProperty(XMPConst.NS_CAMERA_RAW, "Version");
    if (activeDocument.name.match(/-\d+$/) && activeDocument.activeLayer.kind === LayerKind.SMARTOBJECT && activeDocument.layers.length === 1 && crsMeta !== undefined) {
        var origDoc = activeDocument;
        var docName = origDoc.name.replace(/-\d+$/, '');
        origDoc.duplicate(docName, false);
        origDoc.close(SaveOptions.DONOTSAVECHANGES);

    }
}

 

Likes

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 ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

@nedmartin 

 

Please let me know how the script works for you.

Likes

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 ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

Thanks for this script. I'm surprised how quickly it works.

 

Unfortunatly there is an issue. If I open a single RAW file, it works perfectly. However, if I open more than one RAW file at a time, only the most recent opened file is renamed. I almost always open more than one RAW file at a time, due to ACR's batch features, and as far as I can tell, there's no way for me to open them one at a time - if I don't open all of them, ACR just closes and I have to re-open it to open the next file/s.

 

Also, what does this line do? From what I can tell, it's not actually doing anything?

if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

 

On the off-chance it makes any difference, here is the full script I run on "Open Document":

// if file is *.jpeg, RGB 8 bit, then convert to 16 bit
if(
	/jp.?g$/i.test(activeDocument.name)
	&& activeDocument.mode == DocumentMode.RGB
	&& activeDocument.bitsPerChannel == BitsPerChannelType.EIGHT
) {
	activeDocument.bitsPerChannel = BitsPerChannelType.SIXTEEN;

	runMenuItem(app.charIDToTypeID("FtOn")); // FIT TO SCREEN
	// runMenuItem(app.charIDToTypeID("ZmOt")); // ZOOM -
	// runMenuItem(app.charIDToTypeID("ZmIn")); // ZOOM +
	// runMenuItem(app.charIDToTypeID("ActP")); // ACTUAL PIXEL
}

// if file is *.TIFF, then fullscreen it
if(/tiff?$/i.test(activeDocument.name)) {
	runMenuItem(app.charIDToTypeID("FtOn")); // FIT TO SCREEN
}

// if file is *.CR3, then fullscreen it
if(/cr3$/i.test(activeDocument.name)) {
	runMenuItem(app.charIDToTypeID("FtOn")); // FIT TO SCREEN
}

// if file is *.DNG, then fullscreen it
if(/dng$/i.test(activeDocument.name)) {
	runMenuItem(app.charIDToTypeID("FtOn")); // FIT TO SCREEN
}

// if file is 20210912_054920_R6_3054 (object opened from RAW), then fullscreen it
// if(/R6_\d{4}$/i.test(activeDocument.name)) {
// 	runMenuItem(app.charIDToTypeID("FtOn")); // FIT TO SCREEN
// }



/*
Remove Ending Hyphen Digit from ACR Smart Object Files.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/stop-photoshop-adding-number-suffixes-to-documents/m-p/12767371
Stephen Marsh, 22nd February 2022, v1.0
Note: Use the scripts events manager open event to run this script
*/

try {
    // Previously saved doc
    if (activeDocument.path) {}
} catch (e) {
    // Unsaved doc
    if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
    var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
    var crsMeta = xmp.getProperty(XMPConst.NS_CAMERA_RAW, "Version");
    if (activeDocument.name.match(/-\d+$/) && activeDocument.activeLayer.kind === LayerKind.SMARTOBJECT && activeDocument.layers.length === 1 && crsMeta !== undefined) {
        var origDoc = activeDocument;
        var docName = origDoc.name.replace(/-\d+$/, '');
        origDoc.duplicate(docName, false);
        origDoc.close(SaveOptions.DONOTSAVECHANGES);

        runMenuItem(app.charIDToTypeID("FtOn")); // FIT TO SCREEN
    }
}

 

Likes

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 ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied


@nedmartin wrote:

Thanks for this script. I'm surprised how quickly it works.

 

Unfortunatly there is an issue. If I open a single RAW file, it works perfectly. However, if I open more than one RAW file at a time, only the most recent opened file is renamed.

 

I only tested one file at a time... I can confirm your results with multiple docs, with further testing it appears that the open event is only triggered on the last file and not for each file. I'll offer a revised version to process all open documents.

 


 

Also, what does this line do? From what I can tell, it's not actually doing anything?

if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

 

 

It is part of the conditional check to ensure that the script is only applied to documents that have Camera Raw Settings metadata. I copied it from other code, so it may not be required, I didn't check if it was required or not and it seemed better to leave it in there as I didn't know any better.

Likes

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 ,
Feb 22, 2022 Feb 22, 2022

Copy link to clipboard

Copied

@nedmartin 

 

Here is a v2 code that will loop over all open docs. I have tested this with multiple files opened from ACR as smart objects with the new script being triggered by the Script Event Manager. Please let me know how it goes for you...

 

 

/*
Remove Ending Hyphen Digit from ACR Smart Object Files v2.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/stop-photoshop-adding-number-suffixes-to-documents/m-p/12767371
Stephen Marsh, 23rd February 2022, v2.0
Note: Use the scripts events manager open event to run this script
*/

#target photoshop

// CHECK FOR OPEN DOCS
if (documents.length) {

    // LOOP OVER OPEN FILES
    for (var i = 0; i < documents.length; i++) {
        activeDocument = documents[i];
        try {
            // PREVIOUSLY SAVED DOC
            if (activeDocument.path) {}
        } catch (e) {
            // UNSAVED DOC
            if (ExternalObject.AdobeXMPScript === undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
            var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
            var crsMeta = xmp.getProperty(XMPConst.NS_CAMERA_RAW, "Version");
            if (activeDocument.name.match(/-\d+$/) && activeDocument.activeLayer.kind === LayerKind.SMARTOBJECT && activeDocument.layers.length === 1 && crsMeta !== undefined) {
                var origDoc = activeDocument;
                var docName = origDoc.name.replace(/-\d+$/, '');
                origDoc.duplicate(docName, false);
                origDoc.close(SaveOptions.DONOTSAVECHANGES);
                // END OF SCRIPT NOTIFICATION
                app.beep();
            }
        }
    }


    // ALERT IF NO DOCS OPEN
} else {
    alert('You must have a document open!');
}

 

 

 

Likes

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 ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

@nedmartin 

 

So how did the new v2 script work for you?

Likes

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 ,
Feb 23, 2022 Feb 23, 2022

Copy link to clipboard

Copied

I haven't had time to test it extensively but so far it seems to be working great! Thank you!

 

I discovered that it does actually run my script for every RAW file even when I open more than one, but that the activeDocument is the same each time, which is why it was only changing the one document and not working on the others. So it's probably quite inefficient - if I open 4 RAW files, this script runs 4 times, loops through all the documents and does its stuff the first time, and then loops another 3 times but doesn't do anything because it already did it and now their names don't match...

Seems to handle it fine and does exactly what I want, just bothers me slightly that it can't work efficiently on just the newly opened files like it's supposed to... Oh well! Probably a bug in the way Photoshop handles smart objects or files from Adobe Camera RAW I guess.

Likes

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 ,
Feb 24, 2022 Feb 24, 2022

Copy link to clipboard

Copied

LATEST

From my very basic testing, Script Events Manager appears to trigger the script once, when the final doc is opened from ACR (not one doc at a time, they are opened as a single batch). So if you are loading 4 docs as smart objects into Photoshop from ACR, once the 4th final doc is opened then SEM is triggered and my script will loop over all open files.

Likes

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