Skip to main content
anders f
Participating Frequently
May 6, 2020 10:49 AM UTC
Answered

How to check if image includes layers?

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 is closed to new replies. Start a new post to keep the conversation going.
Stephen Marsh
Stephen MarshCorrect answer
Community Expert
May 7, 2020 7:41 AM UTC

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);
    }
};  

 

 

7 replies

Shangara Singh
Inspiring
May 25, 2023 8:09 AM UTC

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

Thanks,

Shangara.

Translate
Shangara SINGH.
Stephen Marsh
Community Expert
Community Expert
May 7, 2020 7:50 AM UTC

Thank you SuperMerlin!

Translate
anders f
anders fAuthor
Participating Frequently
May 7, 2020 8:48 AM UTC

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

Translate
Stephen Marsh
Community Expert
Community Expert
May 7, 2020 9:02 AM UTC

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

Translate
Stephen Marsh
Community Expert
Stephen MarshCommunity ExpertCorrect answer
Community Expert
May 7, 2020 7:41 AM UTC

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);
    }
};  

 

 

Translate
Stephen Marsh
Community Expert
Community Expert
May 7, 2020 7:10 AM UTC

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);
    }
}; 

 

 

 

Translate
Stephen Marsh
Community Expert
Community Expert
May 6, 2020 11:19 PM UTC

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

Translate