Copy link to clipboard
Copied
i drag a image from somewhere(for example:/Users/robberfree/Desktop/test.jpg) to PS,
then convert it to smart object.
can i use script to get the smart object image original source path.
i search the 《photoshop-cc-javascript-ref-2015》document but don't found what i want.
is it possible?
Thanks a lot.(sorry for my poor english)
That's why I said "a bit" 😄 But I didn't intepret question correctly.
In this case you need set-up event listener and then you can catch place event.
Look for "notifiers" in documentation and "arguments". Everthing in script listener log is also in arguments as action descriptor. And you can extract data from this descriptor.
Anyway this value is not stored anywhere in document by default. If you want this value after PS restart you should store it somewhere. Maybe in metatags.
From script listener
...Copy link to clipboard
Copied
If you embed the Smart Object there is no connection to the originally placed file anymore, only with Linked Smart Objects would this work.
Copy link to clipboard
Copied
try {
var ref = new ActionReference();
ref.putEnumerated( charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var layerDesc = executeActionGet(ref);
var soDesc = layerDesc.getObjectValue(stringIDToTypeID('smartObject'));
var thePath = soDesc.getPath(stringIDToTypeID("link"));
alert (thePath);
} catch (e) {};
Copy link to clipboard
Copied
c.pfaffenbichler: I a bit disagree. You can get link to embeded file, but you must open it. If you open embeded SO in PS as new document, then it creates .psb file in temp folder. On Windows: c:\Users\<yourProfileName>\AppData\Local\Temp\
I you close document, the .psb file is still there. It should be removed with Photoshop quit.
File name is stored in:
layer reference > smartObject > fileReference (CC2017)
Folder should be always temp folder.
You can read it only with AM code very similar to your code.
Copy link to clipboard
Copied
I stated
If you embed the Smart Object there is no connection to the originally placed file anymore
so I made no comment about the temp-file but the originally placed file.
But on rereading the original post
i drag a image from somewhere(for example:/Users/robberfree/Desktop/test.jpg) to PS,
then convert it to smart object.
I realise I misinterpreted and that the OP actually describes opening the file and then converting to a Smart Object – that would not change the path of the open file (as long as it has not been saved as a new file).
Copy link to clipboard
Copied
That's why I said "a bit" 😄 But I didn't intepret question correctly.
In this case you need set-up event listener and then you can catch place event.
Look for "notifiers" in documentation and "arguments". Everthing in script listener log is also in arguments as action descriptor. And you can extract data from this descriptor.
Anyway this value is not stored anywhere in document by default. If you want this value after PS restart you should store it somewhere. Maybe in metatags.
From script listener:
var idPlc = charIDToTypeID( "Plc " );
var desc3664 = new ActionDescriptor();
var idIdnt = charIDToTypeID( "Idnt" );
desc3664.putInteger( idIdnt, 4 );
var idnull = charIDToTypeID( "null" );
desc3664.putPath( idnull, new File( "D:\\Photos\\my\\path\\IMG_4419.JPG" ) );
var idFTcs = charIDToTypeID( "FTcs" );
var idQCSt = charIDToTypeID( "QCSt" );
var idQcsa = charIDToTypeID( "Qcsa" );
desc3664.putEnumerated( idFTcs, idQCSt, idQcsa );
var idOfst = charIDToTypeID( "Ofst" );
var desc3665 = new ActionDescriptor();
var idHrzn = charIDToTypeID( "Hrzn" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3665.putUnitDouble( idHrzn, idPxl, 0.000000 );
var idVrtc = charIDToTypeID( "Vrtc" );
var idPxl = charIDToTypeID( "#Pxl" );
desc3665.putUnitDouble( idVrtc, idPxl, 0.000000 );
var idOfst = charIDToTypeID( "Ofst" );
desc3664.putObject( idOfst, idOfst, desc3665 );
executeAction( idPlc, desc3664, DialogModes.NO );
Copy link to clipboard
Copied
thanks Jarda Bereza and c.pfaffenbichler.
setup event listener maybe a little complex for my script.
when i asked the questions,
i just want to reuse the smart object image in my web app.
so i want to know the image source path.
now i just export the smart object image every time in script.
Copy link to clipboard
Copied
If I understand you correctly you may want to use Linked Smart Objects instead of Embedded ones.