title: Cycle through windows of the same application using wmcrtl
body: <p>I am configuring xbindkeys to change window focus using shortcuts.
  For example, I managed to create a shortcut to focus on a an application window, let's say a terminator window:</p>
  
  <pre><code>wmctrl -xa terminator
  </code></pre>
  
  <p>Unfortunately it focuses always at the same terminator window, preventing me to cycle through the terminator windows. </p>
  
  <p>Could you suggest me a command to focus on a terminator window and, if pressed again, will cycle through all the terminator windows, please?</p>
  
  <p><strong>UPDATE 30 Mar 2013</strong></p>
  
  <p>I modified this script 
  <a href="http://lars.st0ne.at/blog/switch%20between%20windows%20within%20the%20same%20application" rel="noreferrer">http://lars.st0ne.at/blog/switch%20between%20windows%20within%20the%20same%20application</a>
  to make a script such that </p>
  
  <pre><code>script.sh NAME
  </code></pre>
  
  <p>focus on application NAME or cycle through all the windows of NAME if a window of it is already focused, but it doesn't work properly.</p>
  
  <p>Here is the script</p>
  
  <pre><code>win_class=$1 # 'terminator' # $1
  
  # get list of all windows matching with the class above
  win_list=$(wmctrl -x -l | grep -i $win_class | awk '{print $1}' )
  
  # get id of the focused window
  active_win_id=$(xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}')
  
  # get next window to focus on, removing id active
  switch_to=$(echo $win_list | sed s/.*$active_win_id// | awk '{print $1}')
  
  # if the current window is the last in the list ... take the first one
  if [ "$switch_to" == '' ];then
     switch_to=$(echo $win_list | awk '{print $1}')
  fi
  
  # switch to window
  wmctrl -i -a $switch_to
  </code></pre>
  
  <p>The script does focus on a windows of the application, and cycle through them until it reach a window, I guess the last created. At that point, cycling doesn't work anymore.</p>