Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I'm trying to run

WID=`xdotool search "Inbox" | head -1`
xdotool windowactivate $WID
xdotool key Up

each time stdout of

$ CAMEL_DEBUG=all evolution

yields "starting idle".

I've come up with this script, which does what I want, but only once, it isn't doing it every time "starting idle" is shown, but only once and stops. I don't know bash good enough to force it to repeat itself endlessly.

exec 3< <(CAMEL_DEBUG=all evolution)

while read line; do
   case "$line" in
   *"starting idle"*)
      echo "'$line' contains staring idle"

    WID=`xdotool search "Inbox" | head -1`
        xdotool windowactivate $WID
        xdotool key Up

      break
      ;;
   *)
      echo "'$line' does not contain starting idle."
      ;;
   esac
done <&3

exec 3<&-

Thanks.

share|improve this question
add comment

2 Answers 2

You could try something a little more complex. First redirect the output of evolution to a file:

CAMEL_DEBUG=all evolution > tmpout

Then make an endless while loop that reads the file and reacts if a string is found:

#!/usr/bin/env bash
while true; do
    while read line; do
    case "$line" in
        *"starting idle"*)
        echo "'$line' contains staring idle"

        WID=`xdotool search "Inbox" | head -1`
        xdotool windowactivate $WID
        xdotool key Up

        break
        ;;
        *)
        echo "'$line' does not contain starting idle."
        ;;
    esac
    done < tmpout
done
share|improve this answer
add comment

The break command terminates the while loop. Drop it.

share|improve this answer
    
I know, this is just an example of what works but only once. Dropping the break command isn't good enough, of course I tried it. Some deeper change in the script is needed to be repeated infinitely, but I don't know how to do this. –  cronilus May 8 '13 at 8:31
    
If dropping break is not sufficient, then it's probably a buffering problem. (For most commands, the output is buffered unless it goes to a terminal.) The expect tool can be used to circumvent these problems. Have a look at that one. –  Uwe May 8 '13 at 8:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.