Skip to main content
dendenis82
Inspiring
March 29, 2025
Answered

Extendscript to detect is current document standalone document or smart object in editing mode.

  • March 29, 2025
  • 2 replies
  • 507 views

Hi people,
Is any working approach to make detection mentioned in title? 
I've tried:

if (doc.path != "" && doc.saved)
{
isStandalone = true;

---------------------------------------------

try { // Check if document has a parent property (indicating it's a Smart Object being edited) if (doc.hasOwnProperty('parent') && doc.parent !== null) {
------------------------------------------------------------------------
No results at the moment.

 

Correct answer Stephen Marsh
quote

Yes, exactly, embedded only.


By @dendenis82

 

Please try the following and let me know how you go:

/* 
Check Test If The Active Document Is An Embedded Smart Object.jsx
Stephen Marsh
v1.0 - 30th March 2025
https://community.adobe.com/t5/photoshop-ecosystem-discussions/extendscript-to-detect-is-current-document-standalone-document-or-smart-object-in-editing-mode/td-p/15239239
*/

checkForEmbeddedSO();

function checkForEmbeddedSO() {
    try {

        var fullPath = app.activeDocument.fullName.toString();
        var winRegex = /\/Temp\//;
        var macRegex = /^\/private\/var\/folders\//;
        var trueString = "The active document appears to be an embedded smart object.";

        if (winRegex.test(fullPath)) {
            alert(trueString);
        } else if (macRegex.test(fullPath)) {
            alert(trueString);
        } else {
            alert("The active document does not appear to be an embedded smart object.");
        }

    } catch (error) {
        alert("Error: " + error.message);
    }
}

2 replies

Stephen Marsh
Community Expert
Community Expert
March 29, 2025

@dendenis82 - Can it be assumed that you are only dealing with embedded smart objects and not linked or generative?

dendenis82
Inspiring
March 29, 2025

Yes, exactly, embedded only.
I have some script that I'm using in standalone file and sometimes in smart object editing mode. So no problem when it's runs inside standalone file, but when script operates inside smart object, it should include save command to see changes in parent document. But if script saves every time on standalone file, I should wait the save command finishing. So I'd like to recognize what document type it operates on to include/exclude save step for that type.

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
March 29, 2025
quote

Yes, exactly, embedded only.


By @dendenis82

 

Please try the following and let me know how you go:

/* 
Check Test If The Active Document Is An Embedded Smart Object.jsx
Stephen Marsh
v1.0 - 30th March 2025
https://community.adobe.com/t5/photoshop-ecosystem-discussions/extendscript-to-detect-is-current-document-standalone-document-or-smart-object-in-editing-mode/td-p/15239239
*/

checkForEmbeddedSO();

function checkForEmbeddedSO() {
    try {

        var fullPath = app.activeDocument.fullName.toString();
        var winRegex = /\/Temp\//;
        var macRegex = /^\/private\/var\/folders\//;
        var trueString = "The active document appears to be an embedded smart object.";

        if (winRegex.test(fullPath)) {
            alert(trueString);
        } else if (macRegex.test(fullPath)) {
            alert(trueString);
        } else {
            alert("The active document does not appear to be an embedded smart object.");
        }

    } catch (error) {
        alert("Error: " + error.message);
    }
}
Inspiring
March 29, 2025

I don't know if I understood correctly
see if this is good for you.

 

if (app.documents.length > 0) {  
var myDocument = app.activeDocument;  
var theName= myDocument.name.match(/(.*)\.[^\.]+$/)[1];  
var thePath = myDocument.path;  
var theLayer = myDocument.activeLayer; 

// check if layer is smart object;  
if (theLayer.kind != "LayerKind.SMARTOBJECT") {
    alert ("ALERT!!!\nThis is not a smart object")}  
else {  
    alert("This is a smart object");
    } 
   } 
dendenis82
Inspiring
March 29, 2025

Thank you for the suggestion.
I think first part of your code makes sense, I mean if path returns alert/zero, then it can be smart object in editing mode.
As for the ping layers, I do need only to sort out is current document saved file or it's just opened on the fly smart object(when I press Save, it will update it in the source document, not saved by the path actually).