How to distinguish whether a smart object is a psd file or ai file by code?

uxp can distinguish the layer type, but it seems that it cannot distinguish the file type of the smart object. In some operations, the smart object needs to be opened for further operations, but I don’t want to open the ai file. Is there a way to distinguish them?

Using BatchPlay, you can check the fileReference property of the smartObject property that’s on the LayerDescriptor.

It can either be a FileReference Object (including a path string) or simply a string like “file.psd”

Here’s some RegEx from stackoverflow to grab just the extension from a string:

function fileExtension(path: string) {
  const re = /(?:\.([^.]+))?$/;
  return re.exec(path)[1];
}
2 Likes

Thank you very much. It really works.