Skip to main content
anders f
Participant
May 6, 2020
Answered

How to check if image includes layers?

  • May 6, 2020
  • 5 replies
  • 3746 views

hej,

 

is it possible in bridge to check if a tiff or psd file includes layers or alpha channels, without opening the file in PS?

 

thank you,

anders

This topic has been closed for replies.
Correct answer Stephen Marsh

And here is one for alpha & spot channels:

 

 

// https://forums.adobe.com/thread/1990912

/*
https://community.adobe.com/t5/bridge/how-to-check-if-image-includes-layers/m-p/11111182
How to check if image includes layers?
*/

// TIFF - PSD - PSB Files with Alpha or Spot Channels to Collection.jsx

#target bridge
if (BridgeTalk.appName == "bridge") {
    alphaFiles = MenuElement.create("command", "Add TIFF - PSD - PSB Files with Alpha or Spot Channels to Collection", "at the end of Tools");
}
alphaFiles.onSelect = function () {
    var fileList = Folder(app.document.presentationPath).getFiles(/\.(tif|tiff|psd|psb)$/i);
    withAlphas = 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 = /Adobe Photoshop Document Data Block/g; // Original code from 2016 for layered TIFF
        var rex = /Alpha |Spot Color /g; // 2020 - "Alpha " & "Spot Color " property found using hex editor
        while ((result = rex.exec(dat)) != null) {
            pos.push(result.index + (result[0].length));
        }
        if (pos.length > 0) withAlphas.push(new Thumbnail(fileList[x]));
        dat = null;
    }
    if (withAlphas.length > 0) {
        var foundFiles = app.createCollection("TIFF - PSD - PSB Files with Alpha or Spot Channels");
        app.addCollectionMember(foundFiles, withAlphas);
    }
};  

 

 

5 replies

Shangara Singh
Inspiring
May 25, 2023

These scripts crash Bridge 2022+. Anyone know a fix?

Thanks,

Shangara.

Shangara SINGH.
Stephen Marsh
Community Expert
Community Expert
May 7, 2020

Thank you SuperMerlin!

anders f
anders fAuthor
Participant
May 7, 2020

Wow! You are a hero! These scripts will help me a lot! Thank you!

Stephen Marsh
Community Expert
Community Expert
May 7, 2020

Thank you, however, I'm just standing in SuperMerlin's shadow.

Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
May 7, 2020

And here is one for alpha & spot channels:

 

 

// https://forums.adobe.com/thread/1990912

/*
https://community.adobe.com/t5/bridge/how-to-check-if-image-includes-layers/m-p/11111182
How to check if image includes layers?
*/

// TIFF - PSD - PSB Files with Alpha or Spot Channels to Collection.jsx

#target bridge
if (BridgeTalk.appName == "bridge") {
    alphaFiles = MenuElement.create("command", "Add TIFF - PSD - PSB Files with Alpha or Spot Channels to Collection", "at the end of Tools");
}
alphaFiles.onSelect = function () {
    var fileList = Folder(app.document.presentationPath).getFiles(/\.(tif|tiff|psd|psb)$/i);
    withAlphas = 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 = /Adobe Photoshop Document Data Block/g; // Original code from 2016 for layered TIFF
        var rex = /Alpha |Spot Color /g; // 2020 - "Alpha " & "Spot Color " property found using hex editor
        while ((result = rex.exec(dat)) != null) {
            pos.push(result.index + (result[0].length));
        }
        if (pos.length > 0) withAlphas.push(new Thumbnail(fileList[x]));
        dat = null;
    }
    if (withAlphas.length > 0) {
        var foundFiles = app.createCollection("TIFF - PSD - PSB Files with Alpha or Spot Channels");
        app.addCollectionMember(foundFiles, withAlphas);
    }
};  

 

 

Stephen Marsh
Community Expert
Community Expert
May 7, 2020

Standing on the shoulders of giants, I hacked this for layered TIF, PSD, PSB:

 

 

// https://forums.adobe.com/thread/1990912

/*
https://community.adobe.com/t5/bridge/how-to-check-if-image-includes-layers/m-p/11111182
How to check if image includes layers?
*/

// TIFF - PSD - PSB Files with Layers to Collection.jsx

#target bridge
if (BridgeTalk.appName == "bridge") {
    layeredFiles = MenuElement.create("command", "Add Layered TIFF - PSD - PSB 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 = /Adobe Photoshop Document Data Block/g; // Original code from 2016 for layered TIFF
        var rex = /8BIMfxrp/g; // 2020 - "8BIMfxrp" property found using hex editor
        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("TIFF - PSD - PSB Files with Layers");
        app.addCollectionMember(foundFiles, withLayers);
    }
}; 

 

 

 

Stephen Marsh
Community Expert
Community Expert
May 6, 2020

I believe that the following script was from SuperMerlin, it is only for layered TIFF files. I am not sure how hard it would be to extend to PSD/PSB or to look for alpha channels.

 

 

// https://forums.adobe.com/thread/1990912
#target bridge
if (BridgeTalk.appName == "bridge") {
    tifLayers = MenuElement.create("command", "Tifs With Layers", "at the end of Tools");
}
tifLayers.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 Text = [];
        var rex = /Adobe Photoshop Document Data Block/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("Tifs With Layers");
        app.addCollectionMember(foundFiles, withLayers);
    }
};  

 

 

 

Prepression - Downloading and Installing Adobe Scripts