Using X11 within Term.app?

sagansstash

Registered
Hey All,

Im fairly new to all this, so please forgive any ignorance on my part.

Recently, I found a piece of code to put into my .cshrc file that supposedly allows me to run X11 from inside apple's Term.app, the purpose being to get a shiny clean menu bar, and automatic text wrapping when you resize a window (something Ive found xgterm in X11 to be lacking)

I would just like to know what the code actually does, how its working, and why it works. It consists of the following:

if ($OSTYPE == "darwin" && !($?DISPLAY) && -e /tmp/.X11-unix/* ) then
set X11_FOLDER = /tmp/.X11-unix
set currentUser = `whoami`
set bb = `/bin/ls -l $X11_FOLDER | grep $currentUser`
set bbb = `echo $bb | awk '{printf(":%d.0", $9);}'`
setenv DISPLAY $bbb
echo "Setting DISPLAY = $bbb"
endif

From my (very) linited understanding, I cant see how this works, but it does seem to.

Thanks very much.
 
All that it takes to make X11 work from terminal.app is to get the DISPLAY environment variable set to the correct value. Often this is just DISPLAY=myhost:0 but not always, when you are using fast user switching for instance you might have more than one user running X11 and that would create different numbers.

Roughly the code you pasted checks to see if it is running on OSX and X11 is running. It then looks for what is basically a PID file associated with the current user and then pulls out the display number from the name of that file. Finally it constructs the display string using the hostname and the display number.

On thing is that this script will fail in cases where you have more than one server running as the same user. This is useful in cases where you need to have two X11 servers running with different color depths. And nothing to worry about since if you need to do that you will have many more pressing problems to address ;)
 
Code:
DISPLAY=:0.0
setenv DISPLAY

That should be all the code you need to get X11 working from Apple's terminal. What that does is specify the address of the display, which in this case is the local machine, at port (??) 0.0
 
Viro, that is the simple answer that works 97.3% of the time. Now, start X11 for a user and then use fast user switching to become a different user. At that point start X11 and try to set the display that way. You will find that the second user's display is :1.0 oops.

The complex code above deals with that case and correctly set the second user's display to :1.0
 
Back
Top