Skip to main content
超吴33089989
Participant
May 2, 2017
Answered

how to get the smart object image source path?

  • May 2, 2017
  • 3 replies
  • 2143 views

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)

This topic has been closed for replies.
Correct answer Jarda Bereza

That's why I said "a bit" :-D 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 );

3 replies

Jarda Bereza
Inspiring
May 2, 2017

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.

c.pfaffenbichler
Community Expert
Community Expert
May 3, 2017

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).

Jarda Bereza
Jarda BerezaCorrect answer
Inspiring
May 3, 2017

That's why I said "a bit" :-D 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 );

c.pfaffenbichler
Community Expert
Community Expert
May 2, 2017

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) {};

c.pfaffenbichler
Community Expert
Community Expert
May 2, 2017

If you embed the Smart Object there is no connection to the originally placed file anymore, only with Linked Smart Objects would this work.