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

Quick way to determine if PSD has text layers

Engaged ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

In the interest of efficiency, without looping over all layers (whould can get slow), is it possible to determine if a .PSD countains or does not contain text layers? 

 

    Sort of like this?

var hasText = app.activeDocument.textLayers;

 - But obviously that won't work.

TOPICS
Actions and scripting

Views

166

Translate

Translate

Report

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
Adobe
Community Expert ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

@Ghoul Fool – XMP metadata:

 

<photoshop:TextLayers>

 

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

It will take me a while to see if I can hack some existing code to search for the text layer metadata.

 

Much faster to post some ExifTool code:

 

exiftool -if '$XMP-photoshop:TextLayerName' -XMP-photoshop:TextLayerName -r 'TOP LEVEL ROOT FOLDER'

 

On Windows, one would use straight " double quotes around a file path that contains word spaces.

 

____________________

 

Alternatively, here is a Bridge Find command:

 

bridge-find.png

 

Votes

Translate

Translate

Report

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
Engaged ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

LATEST

Cheers, Stephen! Got it!

 

For my future self:

var srcDoc = app.activeDocument;
var rawData = srcDoc.xmpMetadata.rawData;
alert(find_text_layers(rawData));


function find_text_layers(str)
{
  var regEx = new RegExp("\<photoshop:TextLayers\>", "gim");
  var results = str.match(regEx);
  if (results) return true;
  else return false;
}

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

And this Bridge script will add tif tiff psd psb files that contain text layers in the current folder to a collection:

 

/*
Files with Text Layers to Collection.jsx
https://community.adobe.com/t5/photoshop-ecosystem-discussions/quick-way-to-determine-if-psd-has-text-layers/td-p/13179161
Based on a script from SuperMerlin
https://community.adobe.com/t5/bridge/how-to-check-if-image-includes-layers/m-p/11111182
How to check if image includes layers?
*/

#target bridge

if (BridgeTalk.appName == "bridge") {
    layeredFiles = MenuElement.create("command", "Files with Text Layers to Collection", "at the end of Tools");
}
layeredFiles.onSelect = function () {
    var fileList = Folder(app.document.presentationPath).getFiles(/\.(tif|tiff|psd|psb)$/i);
    withLayers = new Array();
    for (var x in fileList) {
        var file = fileList[x];
        file.open("r");
        file.encoding = 'BINARY';
        var dat = file.read();
        file.close();
        var result;
        var pos = [];
        var rex = /TySh/g;
        while ((result = rex.exec(dat)) != null) {
            pos.push(result.index + (result[0].length));
        }
        if (pos.length > 0) withLayers.push(new Thumbnail(fileList[x]));
        dat = null;
    }
    if (withLayers.length > 0) {
        var foundFiles = app.createCollection("Files with Text Layers");
        app.addCollectionMember(foundFiles, withLayers);
    }
};  

 

 

Votes

Translate

Translate

Report

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
Community Expert ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

This Photoshop script checks the metadata of an open document. I adapted the code from another script, source unknown ( I'm presuming @SuperMerlin )

 

#target photoshop

if (documents.length) {
   if (ExternalObject.AdobeXMPScript == undefined) ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');
   var xmp = new XMPMeta(activeDocument.xmpMetadata.rawData);
   var textLayer = getArrayItems(XMPConst.NS_PHOTOSHOP, 'photoshop:TextLayers');
   for (var a in textLayer) {
      if (textLayer) {
         alert('This file has one or more text layers...');
         break;
      }
   }
}

function getArrayItems(ns, prop) {
   var arrItem = [];
   var items = xmp.countArrayItems(ns, prop);
   for (var i = 1; i <= items; i++) {
      arrItem.push(xmp.getArrayItem(ns, prop, i));
   }
   return arrItem;
}

 

Votes

Translate

Translate

Report

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