1
votes

I know it sounds confusing but it's simple. New to ps here.

I have a psd with a smart object which opens a psb where there is another smart object layer whose contents I replace each time from a different directory.

With ps script (jsx) I want to figure out the path to the directory of the smart object in the psb file, so when I save the files for web they go in the same directory from where I picked the image from.

1

1 Answers

1
votes

You can find file references and paths in layer Action Descriptors. Note that embedded SOs are stored in the system Temp folder.

var mySO = getSmartObjectReference();

if (mySO.found) {
  alert('Is linked: ' + mySO.linked + '\nFile Name: ' + mySO.fileRef + '\nFile Path: ' + mySO.filePath);
}

function getSmartObjectReference()
{
  try
  {
    var smartObject = {
      found: false,
      fileRef: '',
      filePath: '',
      linked: false,
    };
    var ref, so;
    ref = new ActionReference();
    ref.putProperty(charIDToTypeID("Prpr"), stringIDToTypeID("smartObject"));
    ref.putEnumerated(charIDToTypeID("Lyr "), charIDToTypeID("Ordn"), charIDToTypeID("Trgt"));
    so = executeActionGet(ref).getObjectValue(stringIDToTypeID("smartObject"));
    smartObject.found = true;
    smartObject.linked = so.getBoolean(stringIDToTypeID("linked"));
    smartObject.fileRef = so.getString(stringIDToTypeID("fileReference"));
    if (smartObject.linked) {
      smartObject.filePath = so.getPath(stringIDToTypeID("link"));
    } else {
      smartObject.filePath = Folder.temp + '/' + smartObject.fileRef;
    }
    return smartObject;
  }
  catch (e)
  {
    alert(e);
    return smartObject;
  }
}