Hi,
Below is the script, that I am currently use (JScript):
var LOCK_ICON // global variable that will contain reference to system tray (will be initialized in "FindIconInSystemTray" function)
function ClickIconInSystemTray(sIconTitle, bIsLeftMouseButton, bIsDoubleClick, bRShiftPressed)
{
if(typeof(bIsLeftMouseButton) != "boolean")
bIsLeftMouseButton = false;
if(typeof(bIsDoubleClick) != "boolean")
bIsDoubleClick = false;
if(typeof(bRShiftPressed) != "boolean")
bRShiftPressed = false;
if(FindIconInSystemTray(sIconTitle) == -1)
{
Log.Message("Can't click icon in the system tray, because of icon with '" + sIconTitle + "' title does not exist here!");
return false;
}
try
{
if(bRShiftPressed)
{
Win32API.keybd_event(Win32API.VK_RSHIFT, 0, Win32API.KEYEVENTF_EXTENDEDKEY, 0);
BuiltIn.Delay(500);
}
if(bIsLeftMouseButton)
{
if(bIsDoubleClick)
ICON_TRAY.DblClickItem(sIconTitle + "*", true, skNoShift);
else ICON_TRAY.ClickItem(sIconTitle + "*", true, skNoShift);
}
else
{
if(bIsDoubleClick)
ICON_TRAY.DblClickItemR(sIconTitle + "*", true, skNoShift);
else ICON_TRAY.ClickItemR(sIconTitle + "*", true, skNoShift);
}
if(bRShiftPressed)
{
BuiltIn.Delay(500);
Win32API.keybd_event(Win32API.VK_RSHIFT, 0, Win32API.KEYEVENTF_EXTENDEDKEY | Win32API.KEYEVENTF_KEYUP, 0);
}
}
catch(e)
{
Log.Message("Can't click icon in the system tray!", e.description);
return false;
}
return true;
}
function FindIconInSystemTray(icon_title) // return index of required icon in the system tray
{
var oSysTray = null;
var start = getTime();
do
{
oSysTray = Sys.Process("Explorer").WaitWindow("Shell_TrayWnd", "*", 1, 1000).WaitWindow("TrayNotifyWnd", "*", 1, 1000);
if(! oSysTray.Exists)
continue;
ICON_TRAY = oSysTray.WaitWindow("SysPager", "*", 1, 1000).WaitWindow("ToolbarWindow32", "*Notification Area", 1, 1000);
if(! ICON_TRAY.Exists)
{
oSysTray.Refresh();
BuiltIn.Delay(100);
continue;
}
for(var s=0; s<ICON_TRAY.wButtonCount; s++)
{
if(ICON_TRAY.wButtonText(s, true).indexOf(icon_title) != -1)
return s;
}
ICON_TRAY.Refresh();
BuiltIn.Delay(100);
}
while(getTime() - start < 10000)
return -1;
}