Document.mode is (unfortunately) read-only. To get around this little problem, I wrote the following:
Code: Select allStdlib.convertMode = function(doc, cmode) {
var mode;
switch (cmode) {
case DocumentMode.BITMAP: mode = "BtmM"; break;
case DocumentMode.CMYK: mode = "CMYM"; break;
case DocumentMode.DUOTONE: mode = "DtnM"; break;
case DocumentMode.GRAYSCALE: mode = "Grys"; break;
case DocumentMode.INDEXEDCOLOR: mode = "IndC"; break;
case DocumentMode.LAB: mode = "LbCM"; break;
case DocumentMode.MULTICHANNEL: mode = "MltC"; break;
case DocumentMode.RBG: mode = "RGBM"; break;
default: throw "Bad color mode specified";
}
var desc = new ActionDescriptor();
desc.putClass(cTID("T "), cTID(mode));
executeAction(sTID("convertMode"), desc, DialogModes.NO);
};
// example
doc.mode = DocumentMode.GRAYSCALE; // does not work
Stdlib.convertMode(doc, DocumentMode.GRAYSCALE); // does work
Photoshop does not generate ScriptListener code for a mode change. I got around the 'feature' by doing an 'Insert Menu Item' into an Action. I saved it to an Action File and converted that to XML. I read the XML to get the code I needed for Stdlib.convertMode.
Enjoy.
-X
Changing a Document's color mode
Changing a Document's color mode
See what happens when you stay up for 48 hours programming!
But at least I figured out a consistent way of getting code for menu items that don't generate ScriptListener code. So it wasn't a total waste of time...
That being said, it's time for a beer and some downtime (after I fix my code, of course).
But at least I figured out a consistent way of getting code for menu items that don't generate ScriptListener code. So it wasn't a total waste of time...
That being said, it's time for a beer and some downtime (after I fix my code, of course).
Changing a Document's color mode
Don't feel too bad X, for whatever reason Abobe uses code very much like yours in their 'Warn if RGB' script that ships with CS2. Seems they also forgot about changeMode.
BTW, yours is shorter and more understandable than Abode's
BTW, yours is shorter and more understandable than Abode's