Yes, Steve, the -i with grep
is the answer to the name problem.

And, I assume that the "s
are necessary, because the script failed without them.
Anyway, here is my finished script; hope it helps someone out there (please excuse the comments if they are too obvious, but they won't be to me in, say, 6 months

)
CODE
#!/bin/sh
#
# the following 4 variables are necessary because:
# unfortunately dcop Desktop-Nrs go from 1 to n for Desktops 1 to n, whereas
# wmctrl uses values 0 to n-1 for Desktops 1 to n; therefore, to get the correct
# value (for wmctrl) it is necessary to use a value exactly 1 LESS than that
# used by dcop
#.
dcop_gnu_WS=5
wmctrl_gnu_WS=" 4 "
dcop_kpdf_WS=6
wmctrl_kpdf_WS=" 5 "
error_flag=0
#
# First, check if either of the two programs is already running IN THE INTENDED WS; if
# either is, this script will fail, so it simply terminates immediately.
#
# So, for example, test (using 'wmctrl -l') whether or not gnumeric is running IN WS 5;
# if it is, set the error-flag
if [ "$(wmctrl -l | grep -i gnumeric)" != "" ] &&
[ "$(wmctrl -l | grep -i $wmctrl_gnu_WS)" != "" ]; then
echo "error, gnumeric already running in WS $dcop_gnu_WS, please remove gnumeric from that WS" &&
error_flag=1;
fi
if [ "$(wmctrl -l | grep -i kpdf)" != "" ] &&
[ "$(wmctrl -l | grep -i $wmctrl_kpdf_WS)" != "" ]; then
echo "error, kpdf already running in WS $dcop_kpdf_WS, please remove kpdf from that WS" &&
error_flag=1;
fi
#echo "error_flag="$error_flag
if [ "$error_flag" = "1" ]; then
# either gnumeric or kpdf is running (or both), error; terminate.
echo "terminating... goodbye :(";
else
#
# run the following commands (i.e. start gnumeric and kpdf), using '(' bla bla bla ...')'
# start with '(' on a new line, finish with ');', also on its own new line.
#
(
curws=$(dcop kwin KWinInterface currentDesktop)
dcop kwin KWinInterface setCurrentDesktop $dcop_kpdf_WS
# start kpdf as a background-task (the terminating '&'), then wait until it is ready
# to accept input
kpdf output.pdf &
while [ "$(wmctrl -l | grep -i kpdf)" = "" ]
do
sleep 2
done
echo "kpdf started in ws"$(dcop kwin KWinInterface currentDesktop)
#
echo "kpdf started, starting gnumeric..."
dcop kwin KWinInterface setCurrentDesktop $dcop_gnu_WS
echo "starting gnumeric..."
# start gnumeric as a background-task (the terminating '&'), then wait until it is ready
# to accept input
gnumericfilename1.xls 2>/dev/null &
while [ "$(wmctrl -l | grep -i gnumeric)" = "" ]
do
sleep 2
done
echo "gnumeric started in ws"$(dcop kwin KWinInterface currentDesktop)
#
echo "gnumeric started, returning to original desktop..."
dcop kwin KWinInterface setCurrentDesktop $curws
);
fi
Many thanks