I'm trying to build a script that logs the window title when a different window becomes active. This is what I have so far:
import glib
import dbus
from dbus.mainloop.glib import DBusGMainLoop
def notifications(bus, message):
if message.get_member() == "event":
args = message.get_args_list()
if args[0] == "activate":
print "Hello world"
activewindow = Popen("xdotool getactivewindow getwindowname", stdout=PIPE, stderr=PIPE);
print activewindow.communicate()
DBusGMainLoop(set_as_default=True)
bus = dbus.SessionBus()
bus.add_match_string_non_blocking("interface='org.kde.KNotify',eavesdrop='true'")
bus.add_message_filter(notifications)
mainloop = glib.MainLoop()
mainloop.run()
However, something is apparently wrong with my Popen call, and glib seems to swallow the error. At least, that is what someone on a IRC channel told me. When I remove the Popen
and activewindow.communicate()
calls, everything keeps working and I get a message "Hello world!" printed in the shell whenever I switch to a new window.
With the Popen
and communicate()
calls, the script prints a single "Hello world" and hangs after that.
Does anyone know:
- How I can get a proper error message?
- What I'm doing wrong in my
Popen
call?
Thanks in advance!