satelliteuser083 Posted August 13, 2008 Author Report Share Posted August 13, 2008 I still have a snag, I'm afraid, Steve. The "while" line produces in the following error-message: line 14: [: -eq: unary operator expected The "(wmctrl -l | grep gnumeric)" part works OK in a konsole, so there seems to be a syntax-problem elsewhere. I've tried a few changes to the line (using '(' instead of '[', for example) but I'm absolutely useless at de-bugging bash-syntax, so I'll have to ask you to look at it for me, please. Thanks. Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted August 13, 2008 Report Share Posted August 13, 2008 When I get home today, I will check the syntax. It may be that you left off a space or I just missed a little something. Link to comment Share on other sites More sharing options...
satelliteuser083 Posted August 14, 2008 Author Report Share Posted August 14, 2008 (edited) Well, how about this , Steve? I noticed that the "(wmctrl -l | grep gnumeric)" command didn't work completely correctly in a konsole, so instead of gnumeric filename1 & while [ $(wmctrl -l | grep gnumeric) -eq '' ] do sleep done I tried gnumeric filename1 & while [ "$(wmctrl -l | grep Gnumeric)" = "" ] do sleep 2 done and now it works. Bash didn't like 'sleep' without an argument, so that was easy; also, strangely enough, gnumeric is actually called Gnumeric (with a capital G; you have to use the exact name in the title-bar), which is why the 'while' line jammed up. I'm not sure if I've really solved the syntax-prob, or if it's just sheer coincidence, but I don't much care. Until the next time, that is B) . What's your opinion? Edited August 14, 2008 by satelliteuser083 Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted August 14, 2008 Report Share Posted August 14, 2008 (edited) Possibly...it could be your use of double quotes instead of single quotes, using the = instead of -eq, etc. Sorry, I forgot to look yesterday. Not sure you need the "" around the "$(wmctrl...". I think the case problem and the = sign did the trick...you might, though. What we really should do is grep -i gnumeric which makes the grep case-insensitive, in case they change it. Then I think you're good. Let me know if you do need the "" around "$(wmctrl..." and let me know if you need double instead of single quotes and all that. I guess my bash is rusty. Edited August 14, 2008 by Steve Scrimpshire Link to comment Share on other sites More sharing options...
satelliteuser083 Posted August 15, 2008 Author Report Share Posted August 15, 2008 (edited) Yes, Steve, the -i with grep is the answer to the name problem. B) 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 :unsure: ) #!/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 :thumbs: Edited August 15, 2008 by satelliteuser083 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now