Skip to main content
Known Participant
Oct 13, 2019 5:57 PM UTC
Answered

Bits per channel photoshop scripts

Hello, please tell me how to indicate in the script the conditions "if the document is 8 bits then .... if 16 bits then ...".

Thank you.

This topic is closed to new replies. Start a new post to keep the conversation going.
Chuck Uebele
Chuck UebeleCorrect answer
Community Expert
Oct 13, 2019 10:54 PM UTC
var doc = activeDocument
if(doc.bitsPerChannel == 'BitsPerChannelType.EIGHT'){
    //code here
    }
else if(doc.bitsPerChannel == 'BitsPerChannelType.SIXTEEN'){
    //code here
    }
else{}//not 8 or 16 bit

4 replies

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
Oct 13, 2019 10:54 PM UTC
var doc = activeDocument
if(doc.bitsPerChannel == 'BitsPerChannelType.EIGHT'){
    //code here
    }
else if(doc.bitsPerChannel == 'BitsPerChannelType.SIXTEEN'){
    //code here
    }
else{}//not 8 or 16 bit
Translate
Known Participant
Oct 14, 2019 7:12 AM UTC
Thank you very much!
Translate
Stephen Marsh
Community Expert
Community Expert
Oct 13, 2019 10:48 PM UTC

I have been critical of the new forum search feature, however, in this case it did return a useful result (from 2017, luckily it was not prior to 2016):

 

 

#target photoshop

// community.adobe.com/t5/Photoshop/Bits-per-channel-photoshop-scripts/td-p/10667048
// Bits per channel photoshop scripts
// Credit to Tomas Sinkunas, 2017
//community.adobe.com/t5/Photoshop/How-To-Get-Active-Document-Bit-Depth/m-p/9262550#M106261
// How To Get Active Document Bit Depth

app.bringToFront();

var doc = app.activeDocument;
var bpc = doc.bitsPerChannel;

if (bpc === BitsPerChannelType.ONE) {
    alert("1 bpc");
} else if (bpc === BitsPerChannelType.EIGHT) {
    alert("8 bpc");
} else if (bpc === BitsPerChannelType.SIXTEEN) {
    alert("16 bpc");
} else if (bpc === BitsPerChannelType.THIRTYTWO) {
    alert("32 bpc");
}

 

Translate
Known Participant
Oct 14, 2019 7:14 AM UTC
Thank you! Apparently I still can use the search poorly)
Translate