Refreshing Windows tray icons

Last edited on

Windows sometimes displays tray icons of processes that are no longer running anymore. When hovering the mouse over such an icon it vanishes.

The following script shows how to get rid of these stale tray icons by shortly hovering the mouse over each of them:

import os
import sys

def main():
    aut = "addressbook"
    path = os.environ["SQUISH_PREFIX"] + "/examples/qt/addressbook"

    registerAUT(aut, path)


def hoverOverWindowsTrayIcons():
        children = object.children(waitForObject({"type": "SystemTray"}, 1000))
        for c in children:
            mouseMove(c.x, c.y)
        test.warning("hoverOverWindowsTrayIcons() requires a hooked application and a Squish for Windows license.")

def registerAUT(aut, path, squishserver_host="localhost", squishserver_port=4322):
    s = '"' + os.environ["SQUISH_PREFIX"] + '/bin/squishrunner"'
    s += ' --host ' + squishserver_host
    s += ' port=' + str(squishserver_port)
    s += ' --config addAUT "' + aut + '" "' + path + '"'
    if sys.platform == "win32" and s.endswith('"'):
        s = '"' + s

Please note that the above example assumes a Qt application, but the hoverOverWindowsTrayIcons() function should work on all Squish editions on Windows if there is a hooked application and if the Squish license key contains a Squish for Windows license.