Script To Delete Empty Channels?

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

Colorguy

Script To Delete Empty Channels?

Post by Colorguy »

Having some trouble here as I'm new to scripting. Lets say after running a process on a file I'm left with a number of empty Channels. It could be 1 Channel, 2, 5, whatever as it varies. And each channel contained the word Void. Is there a way to write a script that will delete all channels that include the term "Void"? Or possibly just delete any channels which are simply empty?

Professional AI Audio Generation within Adobe Premiere Pro - Download Free Plugin here

Mike Hale

Script To Delete Empty Channels?

Post by Mike Hale »

Do you mean the channel name is 'void'? And what do you mean by 'empty channel'. A channel can't normally be empty. It can be all white or all black. But to be empty the channel has to be one of the component channels and the document has to be transparent.
Colorguy

Script To Delete Empty Channels?

Post by Colorguy »

What I meant is if unneeded channels were named something like Void 1, Void 2, Void 3, etc. Would there be a way to do a script to select any channel containing the term Void and delete them?

By empty channel (bad choice of terminology on my part), I infer to a channel containing nothing but a white fill. Or possibly better yet, any channel filled with a specific RGB value such as:

R 235
G 235
B 235

So if a channel(s) were filled with those RGB values, they were deleted.
txuku

Script To Delete Empty Channels?

Post by txuku »

Bonjour Colorguy

You can use the search method :

Code: Select alldelVoidChannels();

function delVoidChannels()
{
  for(var channelIndex = 0; channelIndex < app.activeDocument.channels.length; channelIndex++)
  {
    var channelRef = app.activeDocument.channels[channelIndex]
    var channelName = channelRef.name;
    if(channelName.search("void")!=-1 )
    {
      channelRef.remove();
      channelIndex = channelIndex-1;
    }
  }
}
Colorguy

Script To Delete Empty Channels?

Post by Colorguy »

Thank you very much for your help! Easily inserted and duplicated a few times within another script to delete channels no longer required.
txuku

Script To Delete Empty Channels?

Post by txuku »