6

I am trying to run a script that will check internet speed on a linux machine with gui, bring the terminal window down and when the query is finished , the window will come up with the answer. as for the time being- i can take the window down, but not up.

    #!/bin/bash
    xdotool getactivewindow windowminimize
    #xdotool set_window --name speedy
    #xdotool set_window --icon-name speedy
    speedtest-cli --simple

    if [ $? -eq 0 ]
    then
    #xdotool windowactivate speedy
    xdotool windowfocus  #speedy
    xdotool key "F11"
    fi

    exec $SHELL
soBusted
  • 621
  • 2
  • 7
  • 12

3 Answers3

9

xdotool needs to know the window ID for all its actions. You correctly used getactivewindow to obtain the window for the windowminimize command, but you also need to do it for setting its name. So put

xdotool getactivewindow set_window --name speedy

before the minimize line.

Then you can use search to find it for activating later.

xdotool search --name speedy windowactivate

See the manpage sections Window stack and Command chaining for an explanation of how this all works.

The whole script:

#!/bin/bash
# rename the window for finding it again later
xdotool getactivewindow set_window --name speedy
xdotool search --name speedy windowminimize

speedtest-cli --simple

if [ $? -eq 0 ]
then
  xdotool search --name speedy windowactivate
  xdotool key "F11"
fi
JigglyNaga
  • 7,706
  • 1
  • 21
  • 47
  • Thank you for your answer, it worked for me. I also added exec $SHELL so the window wouldn't close after execution. – soBusted Sep 01 '16 at 08:48
4

I don't know how to do it using xdotool, but this is how you can raise a window using wmctrl and switch to fullscreen mode with only one command:

#!/bin/sh
TITLE_OF_WINDOW_TO_BE_RAISED="Tor-Browser"
wmctrl -a $TITLE_OF_WINDOW_TO_BE_RAISED -b add,fullscreen

It also switches to the desktop containing the window and focuses it. -a raises the window, -b add,fullscreen 'adds' the fullscreen property.

Hoov
  • 857
  • 7
  • 13
1

To avoid renaming the window, save its identifier in a bash variable, that can be given back to xdotool for all future actions:

#!/bin/bash
WID=$(xdotool getactivewindow)
xdotool windowminimize $WID

speedtest-cli --simple

if [ $? -eq 0 ]
then
  xdotool windowactivate $WID
  xdotool key "F11" $WID
fi
JigglyNaga
  • 7,706
  • 1
  • 21
  • 47