richelbilderbeek / testing_cpp_gui_applications_tutorial

Tutorial about testing C++ GUI applications
GNU General Public License v3.0
3 stars 0 forks source link

Parse wmctrl output #2

Closed richelbilderbeek closed 8 years ago

richelbilderbeek commented 8 years ago

With

wmctrl -l

I get a list of all windows.

Say I want to get the window with text Secret code:

wmctrl -l | egrep "Secret code"

This will give me a line with multiple fields.

I need the first field, which contains the window ID:

wmctrl -l | egrep "Secret code" | cut -f 1 -d ' '

From here:

h2d(){
  echo "ibase=16; $@"|bc
}
d2h(){
  echo "obase=16; $@"|bc
}

This window ID is in hex, so it must be converted:

#echo "ibase=16; $@"|bc
#echo "ibase=16; `wmctrl -l | egrep "Secret code" | cut -f 1 -d ' '`"|bc
richelbilderbeek commented 8 years ago

Convert to decimal:

printf "%d\n" `wmctrl -l | egrep "Secret code" | cut -f 1 -d ' '`
richelbilderbeek commented 8 years ago

Works:

xdotool windowactivate $(printf "%d\n" `wmctrl -l | egrep "Secret code" | cut -f 1 -d ' '`)
richelbilderbeek commented 8 years ago

Move to the right:

xdotool windowactivate $(printf "%d\n" `wmctrl -l | egrep "Secret code" | cut -f 1 -d ' '`) keydown Right
richelbilderbeek commented 8 years ago

Puts 4242 in window:

xdotool windowactivate $(printf "%d\n" `wmctrl -l | egrep "Secret code" | cut -f 1 -d ' '`) key Right key BackSpace key Right key BackSpace key Right key BackSpace key Right key BackSpace type 4242

Awesome!

richelbilderbeek commented 8 years ago

See the scripts folder for all parsing.