Use Terminal inside GRASS OS X

GRASS X11 inside Mac OS X works like any Grass in any Operating System: the environment is X11 and the default X11 terminal application is xterm.

GRASS OS X is a complete Mac OS X application with the default terminal application: Terminal ( Applications -> Utility -> Terminal )

Terminal application is easier than xterm for many Mac user and it's integrated in Mac OS X but there is a feature that it doesn't have: you cannot open another Terminal window inside Grass with all Grass environment variables. Example: if you digit "xterm &" inside Grass xterm in GRASS X11 you open another xterm window with all Grass environment. In Terminal (GRASS OS X) there is not an equivalent command: a new Terminal inside Grass Terminal is totally cleaned without Grass environment. There are some problems in GRASS OS X: some GRASS commands require xterm.

I have made some changes in GRASS OS X only to bypass xterm. You can see these scripts inside "/Applications/GrassGIS.app/Contents/Resources/app/grass-6.3.0" folder

Changes in etc/grass-run.sh
											---------------------------
											row 5
											if [ "$TERM" = "xterm-color" ] && [ -n "$BASH" ] ; then
											
											Changes in etc/gm/gmtree.tcl
											---------------------------
											row 1167
											 Gm::xmon exec r.digit.sh 
											
											Changes in etc/gm/runandoutput.tcl
											----------------------------------
											rows 219-236
											proc guarantee_xmon {} {
											# if {![catch {open "|d.mon -L" r} input]} {
											# while {[gets $input line] >= 0 } {
											# if {[regexp -nocase {(x[0-9]+).*not running} $line dummy monitor]} {
											# # $monnum is the monitor number
											# #create list of non-running monitors
											# lappend xmonlist $monitor
											# }
											# }
											#
											# }
											# if {[catch {close $input} error]} {
											# puts $error
											# }
											#
											# set xmon [lindex $xmonlist 0]
												spawn d.mon start=gism
											}
											
											
Changes in etc/gis_set.tcl
											--------------------------
											row 453-465
											 -command {
												if { $mingw == "1" } {
												exec -- cmd.exe /c start $env(GISBASE)/etc/set_data
												} else {
												if { $osxaqua == "1"} {
												exec -- $env(GISBASE)/scripts/osxstarttext
												} else {
												exec -- $env(GISBASE)/etc/grass-xterm-wrapper -name xterm-grass \
												-e $env(GISBASE)/etc/grass-run.sh $env(GISBASE)/etc/set_data
												}
												}
												# Now we should refresh the list of locations!
												refresh_loc ;# Could it look like this? Maris.
											 }
											
											
Changes in 7 rows in etc/gm/gmmenu.tcl (all commands with term)
											---------------------------------------------------------------
											row 209
												{command {[G_msg "Create/edit projection information for current location"]} \
												{} "g.setproj" {} -command { exec $env(GISBASE)/etc/gui/scripts/g.setproj.sh > $devnull & }}
											
											row 220
												exec $env(GISBASE)/etc/gui/scripts/r.digit.sh > $devnull &
											
											row 235
												{command {[G_msg "Support file creation and maintenance"]} {} "r.support" {} \
												-command { exec $env(GISBASE)/etc/gui/scripts/r.supportx.sh > $devnull & }}
											
											row 312
												exec $env(GISBASE)/etc/gui/scripts/r.le.setup.sh > $devnull &
											
											row 346
												{command {[G_msg "Edit category values of individual cells for displayed raster map"]} \
												{} "d.rast.edit" {} -command { exec $env(GISBASE)/etc/gui/scripts/d.rast.edit.sh > $devnull & }}
											row 524
												exec $env(GISBASE)/etc/gm/script/i.ortho.photo.sh > $devnull &
											row 534
												{command {[G_msg "Interactive input for supervised classification"]} {} "i.class" {} \
												-command { exec $env(GISBASE)/etc/gui/scripts/i.class.sh > $devnull & }}
											
											
I have added in etc/gui/scripts these 7 shell files
											---------------------------------------------------
											g.setproj.sh
											r.digit.sh
											r.supportx.sh
											r.le.setup.sh
											d.rast.edit.sh
											i.ortho.photo.sh
											i.class.sh
											
											They are similar - it only changes the command name. Example: r.digit.sh
											
											#!/bin/sh
											#
											############################################################################
											#
											# MODULE: r.digit.sh for GRASS 6
											# AUTHOR(S): Lorenzo Moretti; 
											# PURPOSE: Runs r.digit from GRASS OS X Terminal.app (AQUA version)
											#
											#############################################################################
											
											if [ -z "$GISBASE" ] ; then
											 echo "You must be in GRASS GIS to run this program."
											 exit 1
											fi 
											
											# These rows are only for OS X AQUA : it's an AppleScript in osxterm var
											OUTPUT="export PATH=$PATH; export GISRC=$GISRC; export GIS_LOCK=$GIS_LOCK; \
											export GRASS_PAGER=$GRASS_PAGER; export GISBASE=$GISBASE"
											osxterm=`/usr/bin/osascript << EOT
											tell application "Terminal"
												do script with command "$OUTPUT; $GISBASE/etc/grass-run.sh r.digit"
											end tell
											EOT`
											echo "$osxterm" 2>&1
											
***********************************************************************
											Added this script in scripts folder: useful to use a new terminal with
											all Grass environment: in GRASS OS X terminal digit osxterm and return.
											osxterm
											***********************************************************************
											#!/bin/sh
											# Lorenzo Moretti
											# Open a new GRASS OS X terminal window with all env vars: (Terminal.app)
											#
											
											if [ -z "$GISBASE" ]
											then
												echo ""
												echo "You must be in GRASS GIS to run this program"
												echo ""
												exit 1
											fi
											
											if [ ! "$osxaqua" ]
											then
											echo "This script is only for GRASS OS X (Aqua)"
											else
											OUTPUT="export PATH=$PATH; export GISRC=$GISRC; export GIS_LOCK=$GIS_LOCK; \
											export GRASS_PAGER=$GRASS_PAGER; export GRASS_WISH=$GRASS_WISH; \
											export GRASS_TCLSH=$GRASS_TCLSH; export GISBASE=$GISBASE; \
											export GRASS_PROJSHARE=$GRASS_PROJSHARE; export GRASS_VERSION=$GRASS_VERSION; \
											export GRASS_HTML_BROWSER=$GRASS_HTML_BROWSER; \
											export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH; export GRASS_LD_LIBRARY_PATH=$GRASS_LD_LIBRARY_PATH"
											GISDBASE=`g.gisenv GISDBASE`
											LOCATION_NAME=`g.gisenv LOCATION_NAME`
											MAPSET=`g.gisenv MAPSET`
											LOCATION="${GISDBASE?}/${LOCATION_NAME?}/${MAPSET?}"
											osxterm=`/usr/bin/osascript << EOT
											tell application "Terminal"
												do script with command "$OUTPUT; echo \"\r>>> GRASS $GRASS_VERSION OS X Terminal \
												($LOCATION) <<<\r>>> You can use this new terminal for Grass commands <<<\r\""
												set custom title of window 1 to "GRASS $GRASS_VERSION OS X Terminal ($LOCATION_NAME)"
											end tell
											EOT`
											echo "$osxterm" 2>&1
											fi
											
********************************************************************
											Added this script in scripts folder: useful to create a new Location
											at the start.
											osxstarttext
											********************************************************************
											#!/bin/sh
											# Lorenzo Moretti
											# Open a new GRASS OS X terminal: (Terminal.app) - only for new location
											#
											
											if [ ! "$osxaqua" ]
											then
											echo "This script is only for GRASS OS X (Aqua)"
											else
											OUTPUT="export PATH=$PATH; export GISRC=$GISRC; export GIS_LOCK=$GIS_LOCK; \
											export GRASS_PAGER=$GRASS_PAGER; export GISBASE=$GISBASE; \
											GRASS_PROJSHARE=$GRASS_PROJSHARE; export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
											osxterm=`/usr/bin/osascript << EOT
											tell application "Terminal"
												do script with command "$OUTPUT; $GISBASE/etc/grass-run.sh; $GISBASE/etc/set_data"
												set custom title of window 1 to "GRASS: Location"
											end tell
											EOT`
											echo "$osxterm" 2>&1
											fi
											

update 20-May-08

ENEA 2004-2009