Activating a Window using ruby-wmctrl

Installation on Debian

Activating the Iceweasel window

Given Iceweasel is already running on the desktop we will 1st find out its index using the following code:

require 'wmctrl'

a = WMCtrl.instance.windows

a.each.with_index do |x, i|
  puts "%s %s ... %s" % [i, x.wm_class, x.title]
end

Output:

0 pcmanfm.Pcmanfm ... pcmanfm
1 panel.lxpanel ... panel
2 wicd-client.py.Wicd-client.py ... Wicd Network Manager
3 lxterminal.Lxterminal ... james@jessie: ~
4 chromium-browser.chromium-browser ... More XDo examples | Snippets | JamesRobertson.eu - Chromium
5 crx_mpognobbkildjkofajifpdfhcoklimli.vivaldi-preview ... s1.jamesrobertson.eu/do/liveblog/publish/2016/jan/21/isabella
6 wicd-client.py.Wicd-client.py ... Wicd Network Manager
7 Pidgin.Pidgin ... Buddy List
8 kate.Kate ... xdo.rsf – Kate
9 Pidgin.Pidgin ... jeeves_mobile@jamesrobertson.eu
10 Navigator.Tor Browser ... About Tor - Tor Browser
11 Navigator.Iceweasel ... ytaka/ruby-wmctrl · GitHub - Iceweasel
12 pluma.Pluma ... dictionary4.dic2 (jamesrobertson.eu) - pluma

To active the Iceweasel window we simply call the activate method for that instance e.g.

a[11].activate

Resources