How to change X11/Xquartz colour setting to 256 colors Using Bash Script?
The command to change Color: From Display, as shown in X11 Preferences of XQuartz, to  Color: 256 Colors, from the command line in Terminal is:

defaults write org.macosforge.xquartz.X11 depth -int 8



Note: XQuartz should be closed when making this change or the ones below, from the command line or from within a bash script.




To reset it to the default, Color: From Display, use the following:

defaults delete org.macosforge.xquartz.X11 depth


Or: 

defaults write org.macosforge.xquartz.X11 depth -int -1



Note: By default the depth key doesn't exist however, when reset from the GUI to the default, the setting is -1, although either is acceptable to set the default back to Color: From Display.