Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
1

How to read named XMP array items in Extendscript

LEGEND ,
Mar 28, 2024 Mar 28, 2024

TL:DR- I'm trying to read this XMP data with Extendscript and can't figure out how to get LayerText as a string.

 

<photoshop:TextLayers>
<rdf:Bag>
<rdf:li rdf:parseType="Resource">
<photoshop:LayerName>Text 1 </photoshop:LayerName>
<photoshop:LayerText>Text 1 </photoshop:LayerText>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<photoshop:LayerName>Text 2</photoshop:LayerName>
<photoshop:LayerText>Text 2</photoshop:LayerText>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<photoshop:LayerName>Text 3</photoshop:LayerName>
<photoshop:LayerText>Text 3</photoshop:LayerText>
</rdf:li>
</rdf:Bag>
</photoshop:TextLayers>

 

-----------------------------------------------------

 

I'm trying to read the embedded LayerText data in PSD files with Bridge using Extendscript. This is saved in the Photoshop namespace when a file is saved with text layers.

 

I'm unable to figure out how to get a named field, and (of course) the documentation is both opaque and contradictory. I either get errors or empty reads, I've spent a bunch of time with the CC Tools guide (plus I already have experience dealing with XMP.)

 

The PSD is too big and I'm not posting it, you can easily make one yourself- create a new file, add a couple of text layers with simple content, save as PSD. Its not unique to any one file and I'd like to batch this over thousands of files.

Screenshot 2024-03-28 at 9.56.53 AM.pngexpand image

And before you ask, I already wrote a Photoshop script to export all text layers to a file and that works but takes forever since Photoshop has to open each file. And yes I can possibly do it with EXIFTool, but I have other processing and would prefer to just use a Bridge script if possible.

 

Below is the File Info and EXIFTool data, plus my scripting attempts. Its the info in bold that I want.

 

--------------------

File Info:

 

<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 7.1-c000 79.4d2f597, 2021/09/01-20:51:22 ">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<rdf:Description rdf:about=""
xmlns:xmp="http://ns.adobe.com/xap/1.0/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:photoshop="http://ns.adobe.com/photoshop/1.0/"
xmlns:xmpMM="http://ns.adobe.com/xap/1.0/mm/"
xmlns:stEvt="http://ns.adobe.com/xap/1.0/sType/ResourceEvent#"
xmlns:tiff="http://ns.adobe.com/tiff/1.0/"
xmlns:exif="http://ns.adobe.com/exif/1.0/">
<xmp:CreatorTool>Adobe Photoshop 25.6 (Macintosh)</xmp:CreatorTool>
<xmp:CreateDate>2024-03-28T09:02:08-04:00</xmp:CreateDate>
<xmp:ModifyDate>2024-03-28T09:56:02-04:00</xmp:ModifyDate>
<xmp:MetadataDate>2024-03-28T09:56:02-04:00</xmp:MetadataDate>
<dc:format>application/vnd.adobe.photoshop</dc:format>
<photoshop:ColorMode>3</photoshop:ColorMode>
<photoshop:ICCProfile>ProPhoto RGB</photoshop:ICCProfile>
<photoshop:TextLayers>
<rdf:Bag>
<rdf:li rdf:parseType="Resource">
<photoshop:LayerName>Text 1 </photoshop:LayerName>
<photoshop:LayerText>Text 1 </photoshop:LayerText>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<photoshop:LayerName>Text 2</photoshop:LayerName>
<photoshop:LayerText>Text 2</photoshop:LayerText>
</rdf:li>
<rdf:li rdf:parseType="Resource">
<photoshop:LayerName>Text 3</photoshop:LayerName>
<photoshop:LayerText>Text 3</photoshop:LayerText>
</rdf:li>
</rdf:Bag>
</photoshop:TextLayers>
<xmpMM:InstanceID>xmp.iid:8ff4d3d7-9bfb-4c66-9a1c-9ef3ee4a9fc4</xmpMM:InstanceID>
<xmpMM:DocumentID>xmp.did:8ff4d3d7-9bfb-4c66-9a1c-9ef3ee4a9fc4</xmpMM:DocumentID>
<xmpMM:OriginalDocumentID>xmp.did:8ff4d3d7-9bfb-4c66-9a1c-9ef3ee4a9fc4</xmpMM:OriginalDocumentID>
<xmpMM:History>
<rdf:Seq>
<rdf:li rdf:parseType="Resource">
<stEvt:action>created</stEvt:action>
<stEvt:instanceID>xmp.iid:8ff4d3d7-9bfb-4c66-9a1c-9ef3ee4a9fc4</stEvt:instanceID>
<stEvt:when>2024-03-28T09:02:08-04:00</stEvt:when>
<stEvt:softwareAgent>Adobe Photoshop 25.6 (Macintosh)</stEvt:softwareAgent>
</rdf:li>
</rdf:Seq>
</xmpMM:History>
<tiff:Orientation>1</tiff:Orientation>
<tiff:XResolution>960000/10000</tiff:XResolution>
<tiff:YResolution>960000/10000</tiff:YResolution>
<tiff:ResolutionUnit>2</tiff:ResolutionUnit>
<exif:ColorSpace>65535</exif:ColorSpace>
<exif:PixelXDimension>2000</exif:PixelXDimension>
<exif:PixelYDimension>2000</exif:PixelYDimension>
</rdf:Description>
</rdf:RDF>
</x:xmpmeta>

----------------------------------------------------------------

EXIFTool

 

[ExifTool] ExifToolVersion: 12.65
[File] FileName: text test.psd
[File] Directory: /Users/dconverse/Pictures/Product Images/Incoming
[File] FileSize: 24 MB
[File] FileModifyDate: 2024:03:28 09:56:03-04:00
[File] FileAccessDate: 2024:03:28 09:56:04-04:00
[File] FileInodeChangeDate: 2024:03:28 09:56:03-04:00
[File] FilePermissions: -rw-r--r--
[File] FileType: PSD
[File] FileTypeExtension: psd
[File] MIMEType: application/vnd.adobe.photoshop
[Photoshop] NumChannels: 3
[Photoshop] ImageHeight: 2000
[Photoshop] ImageWidth: 2000
[Photoshop] BitDepth: 16
[Photoshop] ColorMode: RGB
[Photoshop] IPTCDigest: 00000000000000000000000000000000
[XMP] XMPToolkit: Adobe XMP Core 9.1-c002 79.dba3da3b5, 2023/12/15-10:42:37
[XMP] CreatorTool: Adobe Photoshop 25.6 (Macintosh)
[XMP] CreateDate: 2024:03:28 09:02:08-04:00
[XMP] ModifyDate: 2024:03:28 09:56:02-04:00
[XMP] MetadataDate: 2024:03:28 09:56:02-04:00
[XMP] Format: application/vnd.adobe.photoshop
[XMP] ColorMode: RGB
[XMP] ICCProfileName: ProPhoto RGB
[XMP] TextLayerName: Text 1 , Text 2, Text 3
[XMP] TextLayerText: Text 1 , Text 2, Text 3
[XMP] InstanceID: xmp.iid:8ff4d3d7-9bfb-4c66-9a1c-9ef3ee4a9fc4
[XMP] DocumentID: xmp.did:8ff4d3d7-9bfb-4c66-9a1c-9ef3ee4a9fc4
[XMP] OriginalDocumentID: xmp.did:8ff4d3d7-9bfb-4c66-9a1c-9ef3ee4a9fc4
[XMP] HistoryAction: created
[XMP] HistoryInstanceID: xmp.iid:8ff4d3d7-9bfb-4c66-9a1c-9ef3ee4a9fc4
[XMP] HistoryWhen: 2024:03:28 09:02:08-04:00
[XMP] HistorySoftwareAgent: Adobe Photoshop 25.6 (Macintosh)
[Photoshop] XResolution: 96
[Photoshop] DisplayedUnitsX: inches
[Photoshop] YResolution: 96
[Photoshop] DisplayedUnitsY: inches
[Photoshop] PrintStyle: Centered
[Photoshop] PrintPosition: 0 0
[Photoshop] PrintScale: 1
[Photoshop] GlobalAngle: 90
[Photoshop] GlobalAltitude: 30
[Photoshop] URL_List:
[Photoshop] SlicesGroupName: Untitled-1
[Photoshop] NumSlices: 1
[Photoshop] PixelAspectRatio: 1
[ICC_Profile] ProfileCMMType: Unknown (KCMS)
[ICC_Profile] ProfileVersion: 2.1.0
[ICC_Profile] ProfileClass: Display Device Profile
[ICC_Profile] ColorSpaceData: RGB
[ICC_Profile] ProfileConnectionSpace: XYZ
[ICC_Profile] ProfileDateTime: 1998:12:01 18:58:21
[ICC_Profile] ProfileFileSignature: acsp
[ICC_Profile] PrimaryPlatform: Microsoft Corporation
[ICC_Profile] CMMFlags: Not Embedded, Independent
[ICC_Profile] DeviceManufacturer: Kodak
[ICC_Profile] DeviceModel: ROMM
[ICC_Profile] DeviceAttributes: Reflective, Glossy, Positive, Color
[ICC_Profile] RenderingIntent: Media-Relative Colorimetric
[ICC_Profile] ConnectionSpaceIlluminant: 0.9642 1 0.82487
[ICC_Profile] ProfileCreator: Kodak
[ICC_Profile] ProfileID: 0
[ICC_Profile] ProfileCopyright: Copyright (c) Eastman Kodak Company, 1999, all rights reserved.
[ICC_Profile] ProfileDescription: ProPhoto RGB
[ICC_Profile] MediaWhitePoint: 0.9642 1 0.82489
[ICC_Profile] RedTRC: (Binary data 14 bytes, use -b option to extract)
[ICC_Profile] GreenTRC: (Binary data 14 bytes, use -b option to extract)
[ICC_Profile] BlueTRC: (Binary data 14 bytes, use -b option to extract)
[ICC_Profile] RedMatrixColumn: 0.79767 0.28804 0
[ICC_Profile] GreenMatrixColumn: 0.13519 0.71188 0
[ICC_Profile] BlueMatrixColumn: 0.03134 9e-05 0.82491
[ICC_Profile] DeviceMfgDesc: KODAK
[ICC_Profile] DeviceModelDesc: Reference Output Medium Metric(ROMM)
[ICC_Profile] MakeAndModel: (Binary data 40 bytes, use -b option to extract)
[Photoshop] PhotoshopThumbnail: (Binary data 1932 bytes, use -b option to extract)
[Photoshop] HasRealMergedData: Yes
[Photoshop] WriterName: Adobe Photoshop
[Photoshop] ReaderName: Adobe Photoshop 2024
[File] ExifByteOrder: Big-endian (Motorola, MM)
[EXIF] Orientation: Horizontal (normal)
[EXIF] XResolution: 96
[EXIF] YResolution: 96
[EXIF] ResolutionUnit: inches
[EXIF] Software: Adobe Photoshop 25.6 (Macintosh)
[EXIF] ModifyDate: 2024:03:28 09:56:02
[EXIF] ColorSpace: Uncalibrated
[EXIF] ExifImageWidth: 2000
[EXIF] ExifImageHeight: 2000
[EXIF] Compression: JPEG (old-style)
[EXIF] XResolution: 72
[EXIF] YResolution: 72
[EXIF] ResolutionUnit: inches
[EXIF] ThumbnailOffset: 306
[EXIF] ThumbnailLength: 0
[Photoshop] LayerCount: 4
[Photoshop] LayerRectangles: 0 0 2000 2000, 235 647 332 1000, 783 1023 1062 1269, 1152 384 1250 737
[Photoshop] LayerBlendModes: Normal, Normal, Normal, Normal
[Photoshop] LayerOpacities: 100%, 100%, 100%, 100%
[Photoshop] LayerVisible: Yes, Yes, Yes, Yes
[Photoshop] LayerNames: Background, Text 1 , Text 2, Text 3
[Photoshop] LayerUnicodeNames: Background, Text 1 , Text 2, Text 3
[Photoshop] LayerColors: None, None, None, None
[Photoshop] LayerModifyDates: 2024:03:28 09:56:02-04:00, 2024:03:28 09:56:02-04:00, 2024:03:28 09:56:02-04:00, 2024:03:28 09:56:02-04:00
[Photoshop] Compression: Uncompressed
[Composite] ImageSize: 2000x2000
[Composite] Megapixels: 4.0

--------------------------------------------

Script example (run from VSCode)

 

 

#target bridge
if(BridgeTalk.appName == 'bridge'){
    try{
        if(ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
        var mthumbs = app.document.selections;
        var md = null;
        var xmp = null;
        var num = 0;
        var lText = null;
        for(var a = 0; a < mthumbs.length; a++){
            if(mthumbs[a].hasMetadata){
                md = mthumbs[a].synchronousMetadata;
                xmp = new XMPMeta(md.serialize());
                if(xmp.doesPropertyExist(XMPConst.NS_PHOTOSHOP, 'TextLayers')){
                    num = xmp.countArrayItems(XMPConst.NS_PHOTOSHOP, 'TextLayers');
                    Window.alert(num.toString());
                    for(var b = 1; b <= num; b++){
                        lText = xmp.getArrayItem(XMPConst.NS_PHOTOSHOP, 'TextLayers', b);
                        // lText = xmp.getProperty(XMPConst.NS_PHOTOSHOP, 'TextLayers');
                        // lText = xmp.getStructField(XMPConst.NS_PHOTOSHOP, 'LayerText', XMPConst.TYPE_TEXT, 'LayerText');
                        Window.alert(lText);
                        }
                    }
                }
            }
        }
    catch(e){
        Window.alert(e + e.line);
        }
    }

 

 

-----------------------------------------------

XMP Specification snippet

text test.pngexpand image

356
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation