Skip to main content
Known Participant
October 13, 2019
Answered

Bits per channel photoshop scripts

  • October 13, 2019
  • 2 replies
  • 1394 views

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 has been closed for replies.
Correct answer Chuck Uebele
var doc = activeDocument
if(doc.bitsPerChannel == 'BitsPerChannelType.EIGHT'){
    //code here
    }
else if(doc.bitsPerChannel == 'BitsPerChannelType.SIXTEEN'){
    //code here
    }
else{}//not 8 or 16 bit

2 replies

Chuck Uebele
Community Expert
Chuck UebeleCommunity ExpertCorrect answer
Community Expert
October 13, 2019
var doc = activeDocument
if(doc.bitsPerChannel == 'BitsPerChannelType.EIGHT'){
    //code here
    }
else if(doc.bitsPerChannel == 'BitsPerChannelType.SIXTEEN'){
    //code here
    }
else{}//not 8 or 16 bit
Known Participant
October 14, 2019
Thank you very much!
Stephen Marsh
Community Expert
Community Expert
October 13, 2019

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

 

Known Participant
October 14, 2019
Thank you! Apparently I still can use the search poorly)