Running X11 programs that require 256 colors or 8-bit display
From OS X Scientific Computing
Contents |
Running X11 with 256 colors and millions of colors simultaneously
Why would you want to do this?
Normally, X11 runs in 24-bit mode, with "millions of colors" being the default. The X11.app preferences permit you to choose other color ranges, like "256 colors" and "thousands of colors". Normally you would not want to use those unless required to do so in order to run a specific program. (Some old X11 programs use 256 colors, for example).
If you have a program that requires 256 colors, setting X11.app to 256 colors is the simplest solution, but often it prevents other programs from functioning properly or at all. At the very least, most other programs will look terrible.
If you want to leave X11.app in its default 24-bit mode, displaying "millions of colors", then it is possible to create a wrapper script.
How does it work?
The principle of this is simple. X11.app uses two programs, Xquartz and quartz-wm. You can invoke these separately under a different DISPLAY variable, and force them to be 8-bit. Here is an example of how to do this for the electron microscopy program called web:
A real life example: web
First, let's rename the real executable:
sudo mv /usr/local/em/spider_web14.18_univ/web/bin/web /usr/local/em/spider_web14.18_univ/web/bin/web.exe
Then, create a wrapper shell script called "/usr/local/em/spider_web14.18_univ/web/bin/web" and make it executable:
#!/bin/zsh -f
DISPLAY=:$$[3]$$[4]
Xquartz $DISPLAY -depth 8 2>/dev/null &
quartz-wm &
# $(dirname $0)/web.exe &
$(dirname $0)/web.exe ; kill "$( ps -axxx | grep "Xquartz $DISPLAY -depth 8" | grep -v grep | awk '{print $1}' )" ;
and
sudo chmod a+x /usr/local/em/spider_web14.18_univ/web/bin/web
Now just invoke it in the normal way.
A bit of explanation:
DISPLAY=:$$[3]$$[4]
randomly sets the display variable to a two-digit random number, eg
DISPLAY=:42
Then,
Xquartz $DISPLAY -depth 8 2>/dev/null &
invokes Xquartz on that DISPLAY channel in 8-bit mode. The garbage output is suppressed.
Then,
quartz-wm &
starts the standard Apple X11 window manager, which ensures the window decorations will be present. Finally,
$(dirname $0)/web.exe ; kill "$( ps -axxx | grep "Xquartz $DISPLAY -depth 8" | grep -v grep | awk '{print $1}' )" ;
starts the program. The kill command is in there to kill Xquartz after the window is closed (assuming this is the desired behavior).

