I'd like to have a list of open windows and its icons and process it with python.
I thought I was close with xprop and wmctrl, but I can't use it for my purpose.
I can get a list of open windows with wmctrl -l
, but no idea how get an icon/icon path for any of the listed controls.
Please, help :)
You can use the module wnck and gtk.
For instance:
import pygtk
pygtk.require('2.0')
import gtk
import wnck
screen = wnck.screen_get_default()
while gtk.events_pending():
gtk.main_iteration(False)
for w in screen.get_windows():
name = w.get_name()
icon = w.get_icon()
...
Where name is a string and icon is a GdkPixbuf.
You can read the API documentation for libwnck at http://developer.gnome.org/libwnck/stable/WnckWindow.html, which is for C. However, for Python you only have to remove the prefix wncK_window. If the documentation say wnck_window_get_name(), then in Python would be my_window.get_name().
libwnk is specific to XWindow, hence you can not use it on MS Windows. In that case, you can use other modules that precisely helps on that. Check the answer for Get list of open windows in Python