Skip to content

Instantly share code, notes, and snippets.

@moluapple
Created November 22, 2011 10:29
Show Gist options
  • Save moluapple/1385381 to your computer and use it in GitHub Desktop.
Save moluapple/1385381 to your computer and use it in GitHub Desktop.
PS_Split Channels to Files
(function (){
var op = new TiffSaveOptions;
op.imageCompression = TIFFEncoding.TIFFLZW;
app.documents.length == 1 && splitChannels (activeDocument);
function splitChannels (doc) {
var fn = doc.name,
fp = doc.path,
md = doc.mode,
base = fn.replace(/\.\w{2,4}$/, ''),
F = function (doc, i){
doc.saveAs(File(fp + '/' + base + '-' + i + '.tif'), op);
doc.close(SaveOptions.DONOTSAVECHANGES);
},
i = null;
// 下面这行适用于CS5 版,CS2试试改为: executeAction(charIDToTypeID( "Opn " ), new ActionDescriptor(), DialogModes.NO);
executeAction(charIDToTypeID( "SplC" ), new ActionDescriptor(), DialogModes.NO);
i = app.documents.length;
if (md == DocumentMode.CMYK) {
for (; --i > -1; F(app.documents[i], i > 3 ? i + 1 : [2,3,4,1][i]));
} else if (md == DocumentMode.MULTICHANNEL) {
for (; --i > -1; F(app.documents[i], i + 1));
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment