ATTENTION: You are viewing a page formatted for mobile devices; to view the full web page, click HERE.

Main Area and Open Discussion > General Software Discussion

Advice needed on AHK script

(1/8) > >>

pilgrim:
I have been looking into ways of removing icons from the system tray that have been left behind by programs that have been 'killed' rather than closed normally.
I tried an app that was suggested on another thread I started on here but it had a side effect of rearranging other icons, so I've kept looking.

On the AHK forums I found an old thread that suggested using a script to move the cursor over the tray, which gets rid of the left over icons if you do it manually.
At the end of the thread was the following script which is supposed to work as it is on Windows 7 but I have tried it without success.
Would somebody who understands AHK cast their eye over it and see what they make of it please?

One thing I am uncertain about is the x/y coordinates, my screen resolution is 1920 x 1080 and the tray is in the default position of bottom right and takes up nearly half the width of the screen.


RefreshTray() {
   WM_MOUSEMOVE := 0x200

   ControlGetPos, xTray,, wTray,, ToolbarWindow321, ahk_class Shell_TrayWnd
   endX := xTray + wTray
   x := 5
   y := 12

   Loop
   {
      if (x > endX)
         break
      point := (y << 16) + x
      PostMessage, %WM_MOUSEMOVE%, 0, %point%, ToolbarWindow321, ahk_class Shell_TrayWnd
      x += 18
   }
}

wr975:
It runs fine here, so I'm assuming that you've problems starting the script. It's a function. You need to call it, else it will do nothing. Add these lines at the beginning.


--- ---#x::
RefreshTray()
Return
Launch the script. Every time you press WINDOWS+x the "RefreshTray" function will run.

Or, just remove the function part and make it a plain normal script.


--- ---   WM_MOUSEMOVE := 0x200

   ControlGetPos, xTray,, wTray,, ToolbarWindow321, ahk_class Shell_TrayWnd
   endX := xTray + wTray
   x := 5
   y := 12

   Loop
   {
      if (x > endX)
         break
      point := (y << 16) + x
      PostMessage, %WM_MOUSEMOVE%, 0, %point%, ToolbarWindow321, ahk_class Shell_TrayWnd
      x += 18
   }

pilgrim:
Thank you, I used your second option and learned two things, first the script probably worked when I originally tried it, second there is a problem, which is probably why I never realised it was working.
When I run this script it only removes one icon at a time, I need it to remove several. (I'm not sure if this is because it does not move far enough to catch anything other than the first orphaned icon.)

To put it in context, I want to add it to two batch files which are shown in replies 9 & 15 of THIS thread.
The first file for Windows 7 (reply 9) has since been modified and there are now 4 programs involved all of which leave icons behind.
So either I need to modify this script to sweep a wider area or I need a way of running it multiple times, either from within the script or from within the batch file.

The version for XP I will need to compile as neither of my XP computers has AHK installed.

Any suggestions will be much appreciated.

wr975:
Someone posted a more advanced "refresh system tray" script

http://www.autohotkey.com/board/topic/80624-notrayorphans/

and also offers the download of a compiled script. If it works, just put NoTrayOrphans.exe" in one of your batch files.

http://www.autohotkey.net/~Nazzal/Other/NoTrayOrphans.exe

Curt:
Someone posted a more advanced "refresh system tray" script http://www.autohotkey.com/board/topic/80624-notrayorphans/ and also offers the download of a compiled script. If it works, just put NoTrayOrphans.exe" in one of your batch files. autohotkey.net /~Nazzal/Other /NoTrayOrp...-wr975 (May 06, 2013, 07:53 AM)
--- End quote ---

HOWEVER:

   [NoTrayOrphans(): post #14] MilesAhead

    Members
    429 posts

Posted 05 October 2012 - 04:36 PM
Hmm, I'm running into something weird. If I compile using AHK_L from >the code<, it seems to work every time. If I have my program call the compressed no icon version you attached, I have to mouse over every time. I've tried it using 10 second delay, and 5 minute delay(for closing an app sitting in the tray) and in either case the compressed version forces me to mouse over.

I'm using Windows Seven 32 bit no SP

--- End quote ---

-so, if the exe doesn't work well for you, it might be a good idea to go and copy the script instead.

Navigation

[0] Message Index

[#] Next page

Go to full version