Jump to content
Macro Express Forums

Reading Tray Icon names


Recommended Posts

Sometimes the name of a tray icon/tooltip contains information about what the process is doing. That same information may not be easily readable in the application. It would be nice to be able to read the icon name and extract the information. I cannot find a way to do it. What is so frustrating is that the "Mouse Move to Tray Icon" command dialog in the Script Editor lists the entire tooltip for each icon. Unfortunately there is no way to read that into a variable when actually running the macro, ie move mouse to the icon using a partial match and read back the entire icon name. I need a "Set String to Icon Name".

Link to comment
Share on other sites

Looks like the weekend Help crew are not up to snuff. I managed to find a solution myself modifying someone else's AutoIt code. Works reasonably well. Below is a demo which puts the full name in %T[2]%:

 

Variable Set String %T[1]%: Prompt
External Script: AutoIt
Text Box Display: Results

 

<VARIABLE SET STRING Option="\x01" Destination="%T[1]%" Prompt="Enter Partial Tray Icon Name" Mask="FALSE" OnTop="FALSE" Left="Center" Top="Center" Monitor="0"/>
<EXTERNAL SCRIPT Language="AutoIt" Dest="%T[2]%" Script="#Include <GuiToolBar.au3>\r\n;Returns full tray button name from partial name passed in param1\r\n\r\nGlobal $hSysTray_Handle, $iSysTray_ButtonNumber\r\nGlobal $sToolTipTitle = $cmdline[1]; param1\r\nGlobal $iSystray_IconText = Get_Systray_IconText($sToolTipTitle)\r\n\r\nIf @Error Then\r\n	MsgBox(16, \"Error\", \"Icon not found in system tray\")\r\n	Exit\r\nElse\r\n	ConsoleWrite($iSystray_IconText)\r\nEndIf\r\n\r\nExit\r\n\r\n;............\r\n\r\nFunc Get_Systray_IconText($sToolTipTitle)\r\n\r\n  ; Find systray handle\r\n	Local $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')\r\n	If @error Then\r\n		MsgBox(16, \"Error\", \"System tray not found\")\r\n		Exit\r\n	EndIf\r\n\r\n  ; Get systray item count\r\n	Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)\r\n	If $iSystray_ButCount = 0 Then\r\n		MsgBox(16, \"Error\", \"No items found in system tray\")\r\n		Exit\r\n	EndIf\r\n\r\n  ; Look for wanted tooltip\r\n	Local $iSystray_ButtonNumber\r\n	For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1\r\n		Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)\r\n		If StringInStr($sText, $sToolTipTitle) = 1 Then Return $sText\r\n	Next\r\n\r\n	Return SetError(1, 0, \"\")\r\n\r\nEndFunc\r\n" Parameters="%T[1]%"/>
<TEXT BOX DISPLAY Title="Results" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs16 Partial Tray Icon Name:  %T[1]%\r\n\\par Full Tray Icon Name:  %T[2]%\\lang1033\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="348" Height="119" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

(edit)

The AutoIt code is fairly generic for doing things in the Tray which is basically a toolbar. The string search in the above only works if the start of the icon name is used (eg mac in macexp.exe). To search anywhere in the name (eg cex in macexp.exe) replace

If StringInStr($sText, $sToolTipTitle) = 1 Then Return $sText

with

If StringInStr($sText, $sToolTipTitle) > 0 Then Return $sText

 

Below is a variation (working on the start string) which does not give individual error messages from AutoIt but returns "error" in %T[2]% which can be handled in ME. That error includes system tray not found, no system tray icons found, tray button not found.

 

<VARIABLE SET STRING Option="\x01" Destination="%T[1]%" Prompt="Enter Partial Tray Icon Name" Mask="FALSE" OnTop="FALSE" Left="Center" Top="Center" Monitor="0"/>
<EXTERNAL SCRIPT Language="AutoIt" Dest="%T[2]%" Script="#Include <GuiToolBar.au3>\r\n;Returns full tray button name from partial name passed in param1\r\n\r\nGlobal $hSysTray_Handle, $iSysTray_ButtonNumber\r\nGlobal $sToolTipTitle = $cmdline[1]; param1\r\nGlobal $iSystray_IconText = Get_Systray_IconText($sToolTipTitle)\r\n\r\nIf @Error Then\r\n	ConsoleWrite(\"error\")\r\n		Exit\r\nElse\r\n	ConsoleWrite($iSystray_IconText)\r\nEndIf\r\n\r\nExit\r\n\r\n;............\r\n\r\nFunc Get_Systray_IconText($sToolTipTitle)\r\n\r\n   ; Find systray handle\r\n	Local $hSysTray_Handle = ControlGetHandle('[Class:Shell_TrayWnd]', '', '[Class:ToolbarWindow32;Instance:1]')\r\n	If @error Then\r\n		Exit\r\n	EndIf\r\n\r\n   ; Get systray item count\r\n	Local $iSystray_ButCount = _GUICtrlToolbar_ButtonCount($hSysTray_Handle)\r\n	If $iSystray_ButCount = 0 Then\r\n		Exit\r\n	EndIf\r\n\r\n   ; Look for wanted tooltip\r\n	Local $iSystray_ButtonNumber\r\n	For $iSystray_ButtonNumber = 0 To $iSystray_ButCount - 1\r\n		Local $sText = _GUICtrlToolbar_GetButtonText($hSysTray_Handle, $iSystray_ButtonNumber)\r\n		If StringInStr($sText, $sToolTipTitle) = 1 Then Return $sText\r\n	Next\r\n\r\n	Return SetError(1, 0, \"\")\r\n\r\nEndFunc\r\n" Parameters="%T[1]%"/>
<TEXT BOX DISPLAY Title="Results" Content="{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Tahoma;}{\\f1\\fnil Tahoma;}}\r\n\\viewkind4\\uc1\\pard\\lang4105\\f0\\fs16 Partial Tray Icon Name:  %T[1]%\r\n\\par Full Tray Icon Name:  %T[2]%\\lang1033\\f1 \r\n\\par }\r\n" Left="Center" Top="Center" Width="348" Height="119" Monitor="0" OnTop="FALSE" Keep_Focus="TRUE" Mode="\x00" Delay="0"/>

Edited by JohnS
Link to comment
Share on other sites

  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...