Skip to main content
Inspiring
November 6, 2021
Open for Voting

Save multilayer png/jpg smart objects as psb and automatically replace

  • November 6, 2021
  • 15 replies
  • 2645 views

If I open a smart object, add a layer I want to preserve and hit save, I sometimes get this error:

 

"Can't save this document back to its original file format. Flatten layers and discard extra data as necessary then choose File > Save again. You can save the file using File > Save As, but the associated smart objects will not be updated."

 

Such a self-aware error message! The devs seem to know exactly what I want to do and are offering workarounds rather than just doing what I want. So my suggestion is: do what I want! When I press ctrl+s, save the multi-layer smart object as a psb instead of a png/jpg, then replace all instances of the existing smart object in the original document while maintaining their translations/styles/filters/etc.

 

Part of my confusion is that dragging a png or jpg into my file results in a png/jpg smart object, whereas if I ctrl+v paste it in then right click layer > Convert to Smart Object, I get a psb smart object. I do both interchangeably, and it's hard to know which format a smart object is before I crack it open and do a bunch of work on new layers I intend to preserve, only to hit this annoying error message which basically says "nah we know what you want but we're too lazy to do it". And it can be a LOT of work to go back and replace smart objects if they've been duplicated, scaled, styled, masked, filtered, and buried in groups.

15 replies

Stephen Marsh
Community Expert
Community Expert
April 6, 2025
Participant
July 30, 2024

omg ... seriously ?? i needed this tip about 8 years ago ... no make that 16 years ago  😂😂😂 ... i am both soooo satisfied to have this mystery solved... but mourning for all the projects i abandoned in the past because i didnt know how to convert a jpg to psb and place it " while maintaining their translations/styles/filters/etc. "  ..... THANK YOU.......              STAY IN SCHOOL, KIDS !!  😂😂😂  AND CALL YOUR MOMS !

marcg68495176
Inspiring
February 22, 2024

Minor flaw aside, this script is extremely helpful. Thank you @Stephen Marsh  for taking the time to create and share, and thank you @c.pfaffenbichler for all the info and testing. Much appreciated.

c.pfaffenbichler
Community Expert
Community Expert
February 15, 2024

As it is not a very likely scenario it does not seem very urgent anyway … 

 

I am not sure what the best approach would be, but maybe the easiest way would be having to start in the containing document with the SO selected and opening that via the Script etc. 

If it is already opened and edited that document should become the active one and one would be sure the SO is the active Layer in the next document down. 

 

Stephen Marsh
Community Expert
Community Expert
February 15, 2024

@c.pfaffenbichler 

 

Good point!

 

I only intended one open parent doc and one open smart object.

 

Both instances of:

 

app.documents.length > 1

 

Could be changed to:

 

app.documents.length == 2

 

However I wanted to have more flexibility for the number of open files, so I was only checking for more than 1 open doc.

 

Let the user beware I guess! Unless you have another idea?

c.pfaffenbichler
Community Expert
Community Expert
February 15, 2024

@Stephen Marsh , there is a scenario where this Script could lead to unintended results. 

Suppose one oppened several of the affected SOs and edited them simultaneously. 

When using the Script the last selected SO in the containing document would be replaced, not necessarily the original SO. 

Stephen Marsh
Community Expert
Community Expert
February 15, 2024

The following script is intended to be run on an edited/open embedded smart object, where you have added layers to a flat file such as a JPEG, where the file will be automatically saved as a PSB and relinked.

 

/*
Create embedded PSB from Edited Smart Object layer.jsx
v1.0 - 15th February 2024, Stephen Marsh
https://community.adobe.com/t5/photoshop-ecosystem-ideas/save-multilayer-png-jpg-smart-objects-as-psb-and-automatically-replace/idi-p/12504206
* NOTE: Run this script on an open, layered embedded smart object to replace it as a PSB file (example, automatically convert an embedded JPEG to PSB)
*/

#target photoshop

// The open doc is a Mac embedded smart object
if (/^\/private\/var\/folders\//.test(app.activeDocument.path) === true && app.documents.length > 1) {
    embeddedToPSB();

// The open doc is a Win embedded smart object
} else if (/\/AppData\/Local\/Temp/.test(app.activeDocument.path) === true && app.documents.length > 1) {
    embeddedToPSB();

// The open doc isn't an embedded smart object
} else {
    alert("It doesn't appear that you are editing the contents of an embedded smart object!");
}


function embeddedToPSB() {
    // Create a temp folder with a "random" name
    var theTempDir = new Folder("~/Desktop/_theTempDir_51dcc44a-e898-47e8-bd34-6c1ecfe67faf");
    if (!theTempDir.exists) {
        theTempDir.create();

        // Save the open edited embedded image to a temp PSB file
        var thePSB = theTempDir + "/" + app.activeDocument.name.replace(/\.[^\.]+$/, '') + ".psb";

        function s2t(s) {
            return app.stringIDToTypeID(s);
        }
        var descriptor = new ActionDescriptor();
        var descriptor2 = new ActionDescriptor();
        descriptor2.putBoolean(s2t("maximizeCompatibility"), true);
        descriptor.putObject(s2t("as"), s2t("largeDocumentFormat"), descriptor2);
        descriptor.putPath(s2t("in"), new File(thePSB));
        descriptor.putBoolean(s2t("lowerCase"), true);
        descriptor.putEnumerated(s2t("saveStage"), s2t("saveStageType"), s2t("saveSucceeded"));
        executeAction(s2t("save"), descriptor, DialogModes.NO);
        app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);

        // Replace the original embedded file with the temp PSB file
        function s2t(s) {
            return app.stringIDToTypeID(s);
        }
        var descriptor = new ActionDescriptor();
        descriptor.putPath(s2t("null"), new File(thePSB));
        executeAction(s2t("placedLayerReplaceContents"), descriptor, DialogModes.NO);

        // Remove the temp PSB before the temp folder can be removed
        thePSB = new File(thePSB);
        thePSB.remove();

        // Remove the empty temp folder
        theTempDir.remove();

        app.beep();

    } else {
        alert("Script cancelled as the temporary desktop folder already exists!");
    }
}

 

https://prepression.blogspot.com/2017/11/downloading-and-installing-adobe-scripts.html

 

Stephen Marsh
Community Expert
Community Expert
February 15, 2024

@marcg68495176 – I'll post a script for you later to automate the process!

c.pfaffenbichler
Community Expert
Community Expert
February 14, 2024

When one places a png or jpg that’s just that: A png or a jpg embedded in the layered file. 

Now I am not claiming that I haven’t done that myself, but those were my own mistakes and replacing the SOs was a (slight) inconvenience. 

But embedding a jpg for example can have (minor) filesize benefits. 

 

Automatically converting to psb would be undesirable in the case of placing ai, eps, svg and pdf because it would destroy the vector content – I am sure the Photoshop team would be able to exclude those formats in an automatic psb-conversion. 

marcg68495176
Inspiring
February 14, 2024
Understood thank you.
c.pfaffenbichler
Community Expert
Community Expert
February 14, 2024

• Save the opened png with its Layers as a psd, psb or tif 

• close it 

• in the containing document Layer > Smart Objects > Replace Content and select that new file

 

So there is no need to »flatten it and work destructively«. (edited)

marcg68495176
Inspiring
February 14, 2024
I didn't know about this replace feature. Thank you for patiently
explaining it. I still don't understand why smart objects are not
automatically psbs and I have to do all of that rather than just edit and
save.