Set DISPLAY Variable in Mac OS X’s Terminal

This is a modification of Edd Edmondson’s tip from his Mac OS X for Astrophysicists. (If you use X11.app and you want it to stop opening xterm check out that page.)

Add the following to your ~/.profile or ~/.bash_profile or whatever. If you don’t have one create ~/.profile by:

 nano -w ~/.profile

and then paste this code into it:

 if [ -e /tmp/.X11-unix/* ]
 then
        X11_FOLDER=/tmp/.X11-unix
        currentUser=`(set `whoami`; echo $1)`
        bb=`ls -l $X11_FOLDER | grep $currentUser`
        bbb=${bb/*X/:}
        usedDISPLAY=$bbb.0
        export DISPLAY=$usedDISPLAY
 fi

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>