Photoshop CS2: Checking the number of channels

This is a repost because I posted this in the wrong forum - sorry about this. :confused:

Is there a way to check the number of channels in a document? That way, if a document is not converted properly to a CMYK image, or if the image has an alpha channel it shouldn’t have, it can act upon it.

Thanks.

Hi w2ed,

From a quick copy/paste from my scripts, (it should work with CS also), this might help

We assume that your doc mode is not Multichannel or Bitmap – can’t convert to cmyk directly – so we skip the error handling


tell application "Adobe Photoshop 7.0"
	if exists document 1 then
		activate
		set display dialogs to never
		repeat while (exists document 1)
			set docRef to current document
			if mode of docRef is not CMYK then
				change mode docRef to CMYK
				delete (every channel of docRef whose kind is not component channel)
			end if
			close docRef saving yes
		end repeat
	end if
end tell

Modify to suite your needs

Yannis A.

[Info] Photoshop Scripting sucks when its a matter of speed (at least for the doc sizes I work with) things should go a lot faster if Spotlight Metadata Attributes supported ‘Alpha channel check’ for cmyck images. If that was the case, you could do the doc checking outside PS a lot faster. i.e.


set colorSpace to last word of (do shell script "mdls -name kMDItemColorSpace ~/Desktop/KLN-616_cw1.tif")
-->RGB

set a to last word of (do shell script "mdls -name kMDItemHasAlphaChannel ~/Desktop/KLN-616_cw1.tif") as integer
--> 0= NO Alpha channels
--> 1= Alpha channels