[GRASS-dev] New xterm wrapper not working on Mac build

I just discovered that the xterm wrapper script does not work for Willaim Kyngesburye’s framework build binaries for the Mac, and won’t work for Lorenzo’s binaries either in some circumstances.

The issue is that the Mac BASH terminal is used as the GRASS terminal rather than an xterm. The Mac terminal is much easier to use. But when grass-xterm-wrapper.sh is run from the BASH terminal, it doesn’t realize that x is running and returns a command not found error. This is not a problem when an xterm is launched from TclTk, which IS running in X-windows.

Solutions?

Michael


Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

Hmm, when I saw the xterm wrapper thread, I kinda wondered how it might affect GRASS running from a Mac Terminal. I'm not sure about the details on how the wrapper is used, but when an xterm is needed, would a Mac Terminal work?

One thing I added to my custom GRASS.app startup is a GRASS_OS_STARTUP env var. I set it to "Mac.app" and it was initially used when I added to the existing grass6 startup shell, but now I use a completely custom grass startup shell because I couldn't figure out how to pass args from the open command. I left GRASS_OS_STARTUP in the startup, so maybe grass-xterm-wrapper can use this to set GRASS_XTERM to open a Terminal instead of an xterm?

It would be kinda tricky - exec'ing a Terminal directly would actually run Terminal.app again instead of creating a new window in an already-running Terminal (not good, most Mac apps are only meant to be run once), instead it would need to be run from 'open' (this is how I start GRASS in my python startup). But this will only work to run a script from a file, not open an empty Terminal window, unless there is no window currently open.

For running a script in a new window (open doesn't need to run from exec, and returns immediately without waiting for the script to run - it's just 'opening' a file in an application):

/usr/bin/open -a Terminal some_script_file.sh

Without a script file, it just opens the Terminal, and if there is no window open, it will open a new one (what we want), but if there is already one open (there is because GRASS was started in one) it will just activate the frontmost window.

I thought about doing an inline AppleScript, but the Terminal's scriptability is surprisingly limited - there is no way to open a new window. It could be done with the System Events scripting to manually choose a menu item, but that's messy and requires a user to activate Universal Access.

If the xterm usage needs specific xterm options, then a Terminal probably won't work, since it doesn't have startup options except for running a script. Which makes me wonder - if an xterm is explicitly needed, that makes it difficult to separate the GUI from X11 if a user wanted to use Tcl/Tk Aqua (or a native Windows TclTk, if that option works).

Or, if the GUI is running in an X11 Tcl/Tk, you probably want xterms for a consistent look.

For running from the CLI, I did a search and the only place an xterm is used is r[3].mapcalculator, to run in 'expert' mode (and without grass-run.sh). That doesn't sound right - won't it be missing the GRASS running environment? Why should it run in a separate window in the first place?

Do you have a specific example of grass-xterm-wrapper use in the CLI that fails?

On Sep 4, 2006, at 2:08 PM, Michael Barton wrote:

I just discovered that the xterm wrapper script does not work for Willaim Kyngesburye’s framework build binaries for the Mac, and won’t work for Lorenzo’s binaries either in some circumstances.

The issue is that the Mac BASH terminal is used as the GRASS terminal rather than an xterm. The Mac terminal is much easier to use. But when grass-xterm-wrapper.sh is run from the BASH terminal, it doesn’t realize that x is running and returns a command not found error. This is not a problem when an xterm is launched from TclTk, which IS running in X-windows.

Solutions?

Michael

-----
William Kyngesburye <kyngchaos@kyngchaos.com>
http://www.kyngchaos.com/

"We are at war with them. Neither in hatred nor revenge and with no particular pleasure I shall kill every ___ I can until the war is over. That is my duty."

"Don't you even hate 'em?"

"What good would it do if I did? If all the many millions of people of the allied nations devoted an entire year exclusively to hating the ____ it wouldn't kill one ___ nor shorten the war one day."

<Ha, ha> "And it might give 'em all stomach ulcers."

- Tarzan, on war

Fiddling around I found out that the following command will open a new
terminal window (assuming that it's where Apple put it), though it's kind of
messy.

open /applications/utilities/terminal.app/contents/macos/Terminal
__________________________________________
Michael Barton, Professor of Anthropology
School of Human Evolution & Social Change
Center for Social Dynamics & Complexity
Arizona State University

phone: 480-965-6213
fax: 480-965-7671
www: http://www.public.asu.edu/~cmbarton

From: William Kyngesburye <woklist@kyngchaos.com>
Reply-To: William Kyngesburye <kyngchaos@kyngchaos.com>
Date: Mon, 4 Sep 2006 16:16:46 -0500
To: Michael Barton <michael.barton@asu.edu>
Cc: <grass-dev@grass.itc.it>
Subject: Re: New xterm wrapper not working on Mac build

Hmm, when I saw the xterm wrapper thread, I kinda wondered how it
might affect GRASS running from a Mac Terminal. I'm not sure about
the details on how the wrapper is used, but when an xterm is needed,
would a Mac Terminal work?

One thing I added to my custom GRASS.app startup is a
GRASS_OS_STARTUP env var. I set it to "Mac.app" and it was initially
used when I added to the existing grass6 startup shell, but now I use
a completely custom grass startup shell because I couldn't figure out
how to pass args from the open command. I left GRASS_OS_STARTUP in
the startup, so maybe grass-xterm-wrapper can use this to set
GRASS_XTERM to open a Terminal instead of an xterm?

It would be kinda tricky - exec'ing a Terminal directly would
actually run Terminal.app again instead of creating a new window in
an already-running Terminal (not good, most Mac apps are only meant
to be run once), instead it would need to be run from 'open' (this is
how I start GRASS in my python startup). But this will only work to
run a script from a file, not open an empty Terminal window, unless
there is no window currently open.

For running a script in a new window (open doesn't need to run from
exec, and returns immediately without waiting for the script to run -
it's just 'opening' a file in an application):

/usr/bin/open -a Terminal some_script_file.sh

Without a script file, it just opens the Terminal, and if there is no
window open, it will open a new one (what we want), but if there is
already one open (there is because GRASS was started in one) it will
just activate the frontmost window.

I thought about doing an inline AppleScript, but the Terminal's
scriptability is surprisingly limited - there is no way to open a new
window. It could be done with the System Events scripting to
manually choose a menu item, but that's messy and requires a user to
activate Universal Access.

If the xterm usage needs specific xterm options, then a Terminal
probably won't work, since it doesn't have startup options except for
running a script. Which makes me wonder - if an xterm is explicitly
needed, that makes it difficult to separate the GUI from X11 if a
user wanted to use Tcl/Tk Aqua (or a native Windows TclTk, if that
option works).

Or, if the GUI is running in an X11 Tcl/Tk, you probably want xterms
for a consistent look.

For running from the CLI, I did a search and the only place an xterm
is used is r[3].mapcalculator, to run in 'expert' mode (and without
grass-run.sh). That doesn't sound right - won't it be missing the
GRASS running environment? Why should it run in a separate window in
the first place?

Do you have a specific example of grass-xterm-wrapper use in the CLI
that fails?

On Sep 4, 2006, at 2:08 PM, Michael Barton wrote:

I just discovered that the xterm wrapper script does not work for
Willaim Kyngesburye¹s framework build binaries for the Mac, and
won¹t work for Lorenzo¹s binaries either in some circumstances.

The issue is that the Mac BASH terminal is used as the GRASS
terminal rather than an xterm. The Mac terminal is much easier to
use. But when grass-xterm-wrapper.sh is run from the BASH terminal,
it doesn¹t realize that x is running and returns a command not
found error. This is not a problem when an xterm is launched from
TclTk, which IS running in X-windows.

Solutions?

Michael

-----
William Kyngesburye <kyngchaos@kyngchaos.com>
http://www.kyngchaos.com/

"We are at war with them. Neither in hatred nor revenge and with no
particular pleasure I shall kill every ___ I can until the war is
over. That is my duty."

"Don't you even hate 'em?"

"What good would it do if I did? If all the many millions of people
of the allied nations devoted an entire year exclusively to hating
the ____ it wouldn't kill one ___ nor shorten the war one day."

<Ha, ha> "And it might give 'em all stomach ulcers."

- Tarzan, on war

See my reply just minutes ago (forgot to cc the list). But this form here really tries to open Terminal as a document. It really should be (and it uses some magic to find Terminal.app):

open -a Terminal

But, like I said, it only opens a new window if one already isn't open. It will if a script is run. And it returns immediately, without waiting for the script to finish.

On Sep 4, 2006, at 6:36 PM, Michael Barton wrote:

open /applications/utilities/terminal.app/contents/macos/Terminal

-----
William Kyngesburye <kyngchaos@kyngchaos.com>
http://www.kyngchaos.com/

All generalizations are dangerous, even this one.

Michael Barton wrote:

I just discovered that the xterm wrapper script does not work for Willaim
Kyngesburye¹s framework build binaries for the Mac, and won¹t work for
Lorenzo¹s binaries either in some circumstances.

The issue is that the Mac BASH terminal is used as the GRASS terminal rather
than an xterm. The Mac terminal is much easier to use. But when
grass-xterm-wrapper.sh is run from the BASH terminal, it doesn¹t realize
that x is running and returns a command not found error. This is not a
problem when an xterm is launched from TclTk, which IS running in X-windows.

Solutions?

  export PATH=$PATH:/usr/X11R6/bin
  export DISPLAY=:0

Or set GRASS_XTERM to a command which will work as a substitute for
xterm. BUT ...

William Kyngesburye wrote:

Hmm, when I saw the xterm wrapper thread, I kinda wondered how it
might affect GRASS running from a Mac Terminal. I'm not sure about
the details on how the wrapper is used, but when an xterm is needed,
would a Mac Terminal work?

Any xterm substitute will need to accept whatever options and switches
are used by commands which were originally written for an xterm.

It's free to ignore them, but it has to figure out that the command is
whatever follows the -e switch. E.g.

  #!/bin/sh
  while true ; do
    if [ "$1" = -e ] ; then break ; fi
    shift
  done
  shift
  exec someotherterminal "$@"

Also, be careful about quoting; some of the commands use -title with
an argument which contains spaces.

--
Glynn Clements <glynn@gclements.plus.com>