1

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?

  • 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. – TomSelleck 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 Answers1

2

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
Radu Rădeanu
  • 169,590