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

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

Explorer ,
Mar 29, 2025 Mar 29, 2025

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.

 

TOPICS
Actions and scripting , Windows
112
Translate
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 , Mar 29, 2025 Mar 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
...
Translate
Adobe
Engaged ,
Mar 29, 2025 Mar 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");
    } 
   } 
Translate
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 ,
Mar 29, 2025 Mar 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).

Translate
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 ,
Mar 29, 2025 Mar 29, 2025

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

Translate
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 ,
Mar 29, 2025 Mar 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.

Translate
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 ,
Mar 29, 2025 Mar 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);
    }
}
Translate
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 ,
Mar 30, 2025 Mar 30, 2025

I have added your piece of code at the end of my script and it works just fine. 
It's detects the embedded smart object without false positive as far as I've tested; It's updates parent file while operating inside smart object and no save alerts while it's working on standalone file(since the file is in read only mode).
Thank you!

Translate
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 ,
Mar 30, 2025 Mar 30, 2025
LATEST

You're welcome. If this is part of a larger script, I would have assumed that you would know if a previous step edited a smart object, but if this was the case, you wouldn't have asked. Glad to be of assistance.

Translate
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