Copy link to clipboard
Copied
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.
1 Correct answer
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
...
Explore related tutorials & articles
Copy link to clipboard
Copied
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");
}
}
Copy link to clipboard
Copied
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).
Copy link to clipboard
Copied
@dendenis82 - Can it be assumed that you are only dealing with embedded smart objects and not linked or generative?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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);
}
}
Copy link to clipboard
Copied
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!
Copy link to clipboard
Copied
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.

