import pyatspi count = 0 def callback(event): global count if event is None: return if type(event) == pyatspi.event.DeviceEvent: return if event.host_application is None: return if event.host_application.name == "Minefield" or event.host_application.name == "Firefox" or event.host_application.name == "Thunderbird": print event count += 1 try: reg = pyatspi.Registry reg.registerEventListener(callback, "document:load-complete") reg.start() except KeyboardInterrupt: print ("Total document:load-complete events:%d") % (count) print "bye"