1

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
6

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
  • Thank you for your answer, it worked for me. I also added exec $SHELL so the window wouldn't close after execution. – Busted Sep 1 '16 at 8:48
3

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.

  • 2
    You should probably use grep -F -e "$TITLE...", in case the title has any special characters in it. – JigglyNaga Aug 31 '16 at 9:27
  • @JigglyNaga Good catch, i edited my answer. Thank you. – Hoov Aug 31 '16 at 13:10
  • @JigglyNaga I just discovered that this can be done with wmctrl alone. – Hoov Aug 31 '16 at 13:17
  • Thank you for the different approach, although I couldn't make it to work.. – Busted Sep 1 '16 at 8:51
0

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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