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)
    startApplication(aut)

    hoverOverWindowsTrayIcons()

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

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
    os.system(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.