#target photoshop
if(documents.length > 0) {
var doc = activeDocument;
main();
};
function main() {
var startRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;
var g = doc.guides;
var gX = new Array();
var n = 1;
gX[0] = 0;
var h = doc.height
for( var i = 0; i < g.length; i++ ) {
if (g[i].direction == Direction.VERTICAL && g[i].coordinate.value !== 0 && g[i].coordinate.value !== doc.width.value) {
gX[n] = g[i].coordinate.value;
n++;
};
};
if (n > 0) {
gX[n] = doc.width.value;
gX.sort(function (a, b) {
return a - b;
});
var ChV = new Array();
for( var i = 0; i < doc.channels.length; i++ ) {
ChV[i] = doc.channels[i].visible;
};
for( var a = 0; a < gX.length-1; a++ ) {
doc.selection.select([[gX[a],0],[gX[a+1],0],[gX[a+1],h],[gX[a],h]], SelectionType.REPLACE, 0, false);
nameChanel = "Slicing select " + a;
try {
doc.channels.getByName (nameChanel);
} catch (error) {
doc.channels.add().name = nameChanel;
};
chRef = doc.channels.getByName (nameChanel);
doc.selection.store(chRef, SelectionType.REPLACE);
};
};
for( var i = 0; i < doc.channels.length; i++ ) {
if (ChV[i]) {
doc.channels[i].visible = true;
} else {
doc.channels[i].visible = false;
};
};
doc.selection.deselect();
app.preferences.rulerUnits = startRulerUnits;
};