Skip to main content
Participating Frequently
February 21, 2022
Answered

Stop photoshop adding number suffixes to documents

  • February 21, 2022
  • 2 replies
  • 3127 views

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 🙂

This topic has been closed for replies.
Correct answer Stephen Marsh

@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!');
}

 

 

 

2 replies

Stephen Marsh
Community Expert
Community Expert
February 22, 2022

@nedmartin 

 

Please let me know how the script works for you.

nedmartinAuthor
Participating Frequently
February 23, 2022

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

 

nedmartinAuthor
Participating Frequently
February 24, 2022

@nedmartin 

 

So how did the new v2 script work for you?


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.

Stephen Marsh
Community Expert
Community Expert
February 21, 2022

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

Stephen Marsh
Community Expert
Community Expert
February 21, 2022

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

    }
}