I'm trying to write a script in Photoshop using JavaScript. The goal for this script is to automatically convert from RGB to Bitmap mode. I don't want use the manual way: image->mode->greyscale->image->mode->bitmap.
After reading the “JavaScript Scripting Reference” I understand that I need to do it the same as the manual way but using code.
I convert the RGB image to grayscale using the changeMode method. This works:
app.activeDocument.changeMode(ChangeMode.GRAYSCALE)
But, when I try to change from greyscale to bitmap I just can´t. The document does not explain clearly how it works. I did try to follow the document but I don't have a lot of experience in JavaScript.
// Save the current preferences
var startRulerUnits = app.preferences.rulerUnits
var startTypeUnits = app.preferences.typeUnits
var startDisplayDialogs = app.displayDialogs
// Set Adobe Photoshop to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
app.displayDialogs = DialogModes.NO
app.activeDocument.changeMode(ChangeMode.GRAYSCALE)
app.activeDocument.changeMode(ChangeMode.Bitmap)
// app.activeDocument.close()
I appreciate your help with providing a simple example about how to do it.