Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to use a script suggested for an answer I asked earlier, however I am having trouble getting it to work.

The script should bring all instances of a program (whose name is passed as an argument) forward.

Here is a copy of the script:

#!/bin/bash

Program=$@

wmctrl -l | while read Window; do
    if [[ "$Window" == *"$Program"* ]]; then
        echo "DEBUG: I bring $Window"
        code=`echo "$Window" | cut -f 1 -d " "`
        wmctrl -i -a $code
    fi
done

I have added a keyboard shortcut in preferences whose command is:

bash /home/michael/Scripts/bring-all-windows.bash  terminal

It works fine for other applications like gedit but I get no response when I try it with terminal, Terminal or gnome-terminal.

Does anybody know why this might happen?

share|improve this question
    
If the answer was not working for you, you should have asked in comments to the author, instead making a new question. –  Braiam Sep 16 '13 at 22:40
    
I tried that but only got radio silence, also I presumed it qualified as a different question. Sorry about that. –  Tom celic Sep 16 '13 at 22:52
    
People get several notifications a day (I get +10 when I'm sleeping) so waiting a prudent time is always desirable (48 hours). If you see that it doesn't work, you should downvote it and comment why it doesnt. –  Braiam Sep 16 '13 at 22:59

1 Answer 1

up vote 1 down vote accepted

The script from the question it works perfectly, but the problem is with your terminal window title which doesn't contain the word (string) "Terminal". To get over this "inadequacy", you have three possibilities:

  1. Make your terminal window to contain the word "terminal". To do this, when you are in terminal, go to EditProfile Preferences (or press Alt+E and then O), select Title and Command tab, and follow the instructions from the below image:

    terminal title

  2. As I see in this image, your terminal window title is the same as your terminal prompt. So, the script will work as expected if you run using the following command:

    /home/michael/Scripts/bring-all-windows.bash michael@michael

    (you don't need to prepend the above command with bash).

  3. Or, maybe the best choice, in the script match with the window identity, not with window title:

    #!/bin/bash
    
    Program=" $(pidof $@) "
    
    wmctrl -lp | while read Window; do
        if [ "${Program/ `echo "$Window" | cut -f 4 -d " "` }" != "$Program" ]; then
            echo "DEBUG: I bring $Window"
            code=`echo "$Window" | cut -f 1 -d " "`
            wmctrl -i -a $code
        fi
    done
    

    Then run the script using the following command:

    /home/michael/Scripts/bring-all-windows.bash gnome-terminal
share|improve this answer

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.