x11 and xterm

Hi…

I am wondering, how can I launch xterm from within applescript?

If I try to do a shell script, I get an XT error “cannot open display”

any thoughts?

do shell script "open -a X11; export DISPLAY=:0.0; export PATH=$PATH:/usr/X11R6/bin; xclock &"

great! thank you very much! Now is there a way I can tell that xterm window to come to the front?

I have modified my x11 so that it is always running in the background and it’s icon is not on my dock… So when I do a script launching xterm, it comes up but the window is not immediately editable without having to click on it first… I tried scripting x11 to find it’s windows, but apparently x11 doesn’t allow that… any ideas?

I see - you want that window to have focus…

well, this is ugly, but this works on the command line (you’ll probably have to escape the double quotes):

do shell script "osascript -l AppleScript -e 'tell application "X11"  to activate'; export DISPLAY=:0.0; export PATH=$PATH:/usr/X11R6/bin; xclock &"

This might be easier as a shell script (this is basically I use to start pan - which I kid you not stands for the “pimp ass newsreader”):

[code]#!/bin/sh

If X11 isn’t running, start the -a app called X11 (anywhere).

if [ -z “ps ax | grep X11.app | grep -v grep” ]; then
open -a X11
else
osascript -l AppleScript -e ‘tell application “X11” to activate’
fi

Set the ONE value we need for X11 apps to work right.

if [ -z “$DISPLAY” ]; then
export DISPLAY=:0.0
fi

pick up Mac OS X’s System Preferences here - set in the International panel

MY_LANG=defaults read .GlobalPreferences "AppleLanguages" | tr -d '\012' | sed 's/(//' | sed 's/ *//' | awk -F "," '{ print $1 }'

case “$MY_LANG” in
en)
LANGUAGE=en_US
;;
"en-GB")
LANGUAGE=en_GB
;;
pl)
LANGUAGE=pl_PL.ISO8859-2
;;
esac

export LANG=$LANGUAGE

this is application specific:

export PATH=$PATH:/usr/X11R6/bin; xclock &

exit[/code]
save it as a plain text file, do a “chmod +x /path/to/script.txt” and then just call on your shell script. Or use Platypus to build a wrapper around it, which is what I do.

Wow… thank you so much!!!

what is weird is that, I made an app of it with platypus but running it didn’t bring the window to focus-- though running it at the command line did… So I ended up making an applescript app that called it via shell, and it works great.

The strange thing is, the applescript application hangs up until xterm quits-- I was going to ask you if there was a way to make it check if Xterm is running, if it was, could it just bring the window to focus rather thtan open another window. But I don’t think thats going to be possible since it hangs until xterm is closed…

Anyway, thanks again!

-patrick