Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 04, 2016, 08:27:28 PM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Last post Author Topic: Advice needed on AHK script  (Read 8576 times)

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Advice needed on AHK script
« on: May 05, 2013, 09:12:35 AM »
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
   }
}
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

wr975

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 369
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #1 on: May 05, 2013, 11:20:44 AM »
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

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #2 on: May 06, 2013, 03:22:48 AM »
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.
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

wr975

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 369
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #3 on: May 06, 2013, 07:53:33 AM »
Someone posted a more advanced "refresh system tray" script

http://www.autohotke...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.autohotke...er/NoTrayOrphans.exe

Curt

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 7,089
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #4 on: May 06, 2013, 08:31:43 AM »
Someone posted a more advanced "refresh system tray" script http://www.autohotke...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...

HOWEVER:

Quote
   [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

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

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #5 on: May 06, 2013, 09:04:31 AM »
Thanks for the links but no joy.

To start with, since I added the fourth program to my batch file the original script now removes 2 icons at a time.

Regarding the links:
The exe does not work, one of the posters in the link had the same trouble.
The script at the bottom of the page did not work either.
The script at the top of the page removed 2 icons the same as my original script now does but it is 8 times the size.

I have just spent the last hour trying different variations on the original script.
I tried altering the x numbers, nothing.
I tried pushing the loop as high as x20, nothing.

So I am back to the idea of running the script more than once.
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,473
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #6 on: May 06, 2013, 09:25:53 AM »
And yet another option :)

Here's a simple AutoIt script that will bounce the mouse over tray icons that have a running process, it may pick up orphaned icons as it jumps from one to another.

It's just a modified version of the SysTray_Example.au3 found here along with the UDF by tuape.

Attached code redundant - see below.
« Last Edit: May 07, 2013, 01:19:31 AM by 4wd »

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #7 on: May 06, 2013, 11:29:44 AM »
I think I'll cry.

4wd,

ClearTray.exe did absolutely nothing. While CleanTray.exe which you uploaded on another thread of mine a week ago works perfectly except for one thing, however many icons it deletes it leaves that number of empty spaces on the right hand end of the tray and rearranges any icons it closes the next time they start as well as the icons of any programs that happen to be open at the time.

I realise that AutoIt and AHK are two different languages but it seems that we have one script that removes ALL orphaned icons but plays havoc with icon location and a second script that only affects orphaned icons but will not remove more than 2 at a time. Putting aside the different languages they are written in what are they actually doing differently?


Sometime later:

This has got to be the worst idea for an AHK script that anybody ever came up with but it works:

I went back to the original script and copied it, then I pasted it below the original, I did the same thing until I had 4 copies one below the other and then saved it.
Guess what? It worked.


Sometime later still:

I think I've found the answer to empty spaces at the right hand end of the tray.
I have compiled the script and added it to my batch file where it works perfectly but if I have the Task Manager open when I run it then I get empty spaces in the tray, if I shut the Task Manager down everything in the tray moves to the right and the spaces disappear.
If the Task Manager is not open when I run the batch file, no spaces?
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,473
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #8 on: May 06, 2013, 11:46:30 PM »
The one question I have to ask is: What are you doing that leaves so many orphaned icons so often?

Also, I'd be interested to know if the attached version of CleanTray works, I've modified it so that it works one of two ways which I'll refer to as Nuke'em and Boring :)

CleanTray.exe [anything]

Where: [anything] = anything, any argument at all.

A number from 1 to 100 = Boring slow way = moving mouse over all the icons, the lower the number the faster it moves, I suggest you start with 5.
No args, a string or 0 = Nuke'em = Much faster with an absolute total disregard of resulting icon order, (the way I like since I have to restart explorer.exe to get all the icons to show up in the first place).

So in your case, try:

C:\> CleanTray.exe 2


Quote
I realise that AutoIt and AHK are two different languages but it seems that we have one script that removes ALL orphaned icons but plays havoc with icon location and a second script that only affects orphaned icons but will not remove more than 2 at a time. Putting aside the different languages they are written in what are they actually doing differently?

AutoIt script, (original CleanTray), gets the number of icons in the tray then asks for the process that controls that icon.  If no process is returned the icon is removed - obviously in using the appropriate system calls to remove the icon, it also removes the positioning info.

The first AutoHK script moves the mouse over the icons but you need to specify a coordinate offset based on your screen parameters.  The second AutoHK script works the same as CleanTray by using system calls to detect icons without processes and then removing them.

The new CleanTray works depending on the passed argument:
a) The original way, ie. just removes the icon if it has no background process.
b) Locates the tray, gets the number of icons, it then loops backwards through the list getting the icon' background process.  If an icon has no background process, the mouse is moved to it, Windows will then remove it, (as it usually does).  If an icon is removed it will exit the loop, get the new number of icons and start again, ie. it will recurse, (kind of), through the icon list until it gets to the point where no icons are removed.

REDUNDANT: See below
« Last Edit: May 17, 2013, 10:52:25 PM by 4wd »

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #9 on: May 07, 2013, 09:55:07 AM »
Quote
The one question I have to ask is: What are you doing that leaves so many orphaned icons so often?

The answer to that is in the thread I linked to in reply 2 of this thread.
I have since added Network Activity Indicator to the list as I only need it running when connected, so every time I go offline I have 4 orphan icons.

Quote
Also, I'd be interested to know if the attached version of CleanTray works.

I'm on my Netbook at the moment, I'll try it out when I get back on my main PC.

Quote
AutoIt script, (original CleanTray), gets the number of icons in the tray then asks for the process that controls that icon.  If no process is returned the icon is removed - obviously in using the appropriate system calls to remove the icon, it also removes the positioning info.

The first AutoHK script moves the mouse over the icons but you need to specify a coordinate offset based on your screen parameters.  The second AutoHK script works the same as CleanTray by using system calls to detect icons without processes and then removing them.

I had a feeling that the difference was something along those lines but I didn't understand the scripts well enough to be sure. Thanks for telling me.

Quote
The new CleanTray works depending on the passed argument:
a) The original way, ie. just removes the icon if it has no background process.
b) Locates the tray, gets the number of icons, it then loops backwards through the list getting the icon' background process.  If an icon has no background process, the mouse is moved to it, Windows will then remove it, (as it usually does).  If an icon is removed it will exit the loop, get the new number of icons and start again, ie. it will recurse, (kind of), through the icon list until it gets to the point where no icons are removed.

That sounds involved. I was interested in your comment about the speed of the program.
When I ran the program I made yesterday on Windows 7 it was pretty quick, once the connection had shut down the NAI icon just had enough time to go grey (indicating no connection) before all 4 icons disappeared virtually together.
I added it to my Netbook earlier (XP) and it takes 2 or 3 seconds for everything to shut down and disappear with only 3 icons, there is of course a tremendous resource difference.
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,473
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #10 on: May 07, 2013, 08:24:35 PM »
Seems to me that you'd be better off with a program that terminates a process and removes
any tray icon left by the terminated program, then you'd only need three lines in your batch file.

Or a task killer that sends a proper program exit command so the program can shut itself down cleanly.

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #11 on: May 08, 2013, 05:24:03 AM »
Just tried the new version of CleanTray, it removed all 4 icons instantly, it left 4 empty spaces at the right hand end of the tray (with the Task Manager NOT running), it rearranged the icons. Basically it's doing the same as the previous version.

It would appear to be true that it is the taskkill command that is causing the icons to be left behind but I could not find anything else that would shut all 3 (XP) or 4 (7) programs down and remove the icons at the same time.

The program I put together from the script I found works, as I said above the way I put it together may not be very elegant but what surprised me was that I finished up with a 2kb script while the other 2 scripts I found at the same time are both 8kb.
Not only does it work but it has no unwanted side effects like leaving empty spaces or rearranging icons, anything else we came up with might be more elegant but it would not do a better job.

I think I'll leave this one as is and try to sort out the few other's I am working on. :)
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,473
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #12 on: May 08, 2013, 06:44:35 AM »
Just tried the new version of CleanTray, it removed all 4 icons instantly, it left 4 empty spaces at the right hand end of the tray (with the Task Manager NOT running), it rearranged the icons. Basically it's doing the same as the previous version.

And that's running it as:

CleanTray.exe 5

(or at least some number from 1 to 100) ?

The fact you said instantly kind of indicates that you didn't specify an argument, otherwise you'd be able to watch the mouse move around, ie. it's not instant.

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #13 on: May 08, 2013, 07:20:17 AM »
That deserves my apologies, my amazement and my amusement.

The apology: I am trying to keep up with too many things at once and because I downloaded the file on a different computer I completely forgot about the argument requirement and never reread your post.  :-[  :-[

The amazement: That works incredibly smoothly, I set it to 5 as you suggested but if I use it instead of what I am using, which I suspect I will, I will probably lower it. :Thmbsup:

The amusement: I actually found it quite funny watching the cursor moving about. When I get the time I think I'll set it to 100 and let it have a longer run. :D


EDIT: I never found out till some time later but it is still rearranging icons. The icons that it is removing reopen in the same order/places but programs that were not running at the time are putting their icons in different to usual places when they are opened. Sorry.
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi
« Last Edit: May 08, 2013, 10:22:12 AM by pilgrim »

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,473
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #14 on: May 09, 2013, 07:03:43 AM »
I've given up - your system is just plain weird.  :D

However, a little something for you to try just for the fun of it:

In theory, no left over icons because the programs are cleanly shut down.

I've only tested with those 3 programs so who knows what else can happen.

BTW, why do you run a separate time service?

You could just run w32tm /resync if you want to synchronise your system clock - one less program to kill badly :)
« Last Edit: May 11, 2013, 01:20:14 AM by 4wd »

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #15 on: May 09, 2013, 07:43:03 AM »
Quote
I've given up - your system is just plain weird.  :D

I know the OS thinks it's got a mind of its own.  :)

Quote
In theory, no left over icons because the programs are cleanly shut down.
I've only tested with those 3 programs so who knows what else can happen.

With a name like that it sounds like the software equivalent of Arnie.  :huh:

Quote
BTW, why do you run a separate time service?
You could just run w32tm /resync if you want to synchronise your system clock - one less program to kill badly :)

Partly through habit, I've been using it nearly as long as I've had a computer, partly because I didn't want to use the built in service, partly because it's very easy to set up both in terms of using my own server list and how often it runs, partly because it uses very few resources and it puts an icon in the system tray which shows the last time it synchronised, having it set to run every 15 minutes gives a good indication of firewall/connection problems for very little cost in terms of resources.
Having just looked up your suggestion I'll stick with D4.
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #16 on: May 09, 2013, 10:40:16 AM »
"Arnie" never moved anything.  :(

If you decide to try again the fourth program in 7 is 'NetworkIndicator.exe' (not needed in XP) but I think my system tray is as determined as you are. :)

I asked you before about how the various scripts were different, does the AHK script in reply 1 translate into AutoIt or is that what you have been trying?
Because so far that is still the only thing that has worked without side effects.
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,473
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #17 on: May 11, 2013, 07:19:44 AM »
"Arnie" never moved anything.  :(

It doesn't "move" anything, all it does is send a WM_CLOSE message to the process, (which worked 100% of the time for D4 here), and if that failed it went to the tray icon, opened it's menu and chose the last item, (normally Exit/Quit - that had a ~95% success rate on the other two programs).  ie. You use it to end the processes instead of taskkill.

Quote
I asked you before about how the various scripts were different, does the AHK script in reply 1 translate into AutoIt or is that what you have been trying?

Tested on XP x86, Win7 x64 and Win8 x86, (medium, high and low spec hardware respectively).

CLI use only.

CleanTray: Clears orphaned icons from Notification Area

CleanTray.exe [/debug] [/once] [/timer] [/mensa] [/nuke]
Where: /debug - outputs debug information to the console
           /once  - only runs over the Notification Area once (only valid for default method)
           /timer - displays time taken at the end
           /mensa - only moves mouse to orphaned icons
           /nuke  - blitzes the tray using system calls (icon positions will be lost)
           /pilgrim - adds a 1ms delay between mouse movements

Default method is to traverse the tray using the mouse.

The default method is the slowest if there is more than one icon to remove and /mensa has priority over /nuke if you happen to enter both on the command line.

Code: AutoIt [Select]
  1. #NoTrayIcon
  2. #region ;**** Directives created by AutoIt3Wrapper_GUI ****
  3. #AutoIt3Wrapper_UseUpx=n
  4. #AutoIt3Wrapper_Change2CUI=y
  5. #AutoIt3Wrapper_Res_Fileversion=0.2.0.20
  6. #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=y
  7. #endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
  8.  
  9. #include <Array.au3>
  10. #include <_SysTray.au3>
  11. #include <_OsVersionInfo.au3>
  12.  
  13. Global $debug = False, $once = False, $timer = False, $method = 0, $pilgrim = False
  14.  
  15. If $CmdLine[0] > 0 Then
  16.         For $i = 1 To $CmdLine[0]
  17.                 Switch StringLower(StringStripWS($CmdLine[$i], 8))
  18.                         Case "/debug", "/d"
  19.                                 $debug = True
  20.                         Case "/once", "/o"
  21.                                 $once = True
  22.                         Case "/timer", "/t"
  23.                                 $timer = True
  24.                         Case "/mensa", "/m"
  25.                                 $method = 1
  26.                         Case "/nuke", "/n"
  27.                                 If $method <> 1 Then $method = 2
  28.                         Case "/pilgrim", "/p"
  29.                                 $pilgrim = True
  30.                         Case Else
  31.                                 _DisplayUsage()
  32.                                 Exit
  33.                 EndSwitch
  34.         Next
  35.  
  36. Global $posTray = WinGetPos(_FindTrayToolbarWindow()) ; find the tray
  37. If $method <> 2 Then
  38.         $oldPos = MouseGetPos() ; save mouse position
  39.         MouseMove($posTray[0], $posTray[1], 0) ; move mouse to tray
  40.         WinWait("[CLASS:Shell_TrayWnd]", "", 5) ; wait for the tray to open if hidden
  41.  
  42. If $debug Then
  43.         ConsoleWrite("Desktop Width: " & @DesktopWidth & @CRLF & "Desktop Height: " & @DesktopHeight & @CRLF)
  44.         ConsoleWrite("Notification area dimensions: " & _ArrayToString($posTray, ",") & @CRLF)
  45.         $delay = 1
  46.         $delay = 0
  47.  
  48. If $timer Then $start = TimerInit()
  49. Switch $method
  50.         Case 0
  51.                 $count = 1
  52.                 $ret = 0
  53.                 $j = 0
  54.                 While $count <> $ret
  55.                         $j += 1
  56.                         $count = _SysTrayIconCount()
  57.                         $ret = _SeeYouNextYear()
  58.                         If $once Then ExitLoop
  59.                 WEnd
  60.         Case 1
  61.                 _TharHeIsGetIm()
  62.         Case 2
  63.                 _NukeEmAll()
  64.         Case Else
  65. If $timer Then ConsoleWrite("Time: " & Round(TimerDiff($start) / 1000, 2) & " seconds")
  66. If $method <> 2 Then MouseMove($oldPos[0], $oldPos[1], 0) ; move mouse back where it came from
  67.  
  68. Func _DisplayUsage()
  69.         Local $data = "CleanTray: Clears orphaned icons from Notification Area" & @CRLF & @CRLF & _
  70.                         "CleanTray.exe [/debug] [/once] [/timer] [/mensa] [/nuke]" & @CRLF & _
  71.                         "Where: /debug - outputs debug information to the console" & @CRLF & _
  72.                         "       /once  - only runs over the Notification Area once" & @CRLF & _
  73.                         "                (only valid for default method)" & @CRLF & _
  74.                         "       /timer - displays time taken at the end" & @CRLF & _
  75.                         "       /mensa - only moves mouse to orphaned icons" & @CRLF & _
  76.                         "       /nuke  - blitzes the tray using system calls" & @CRLF & _
  77.                         "                (icon positions will be lost)" & @CRLF & _
  78.                         "Default method is to traverse the tray using the mouse." & @CRLF
  79.         ConsoleWrite($data)
  80. EndFunc   ;==>_DisplayUsage
  81.  
  82. Func _SeeYouNextYear()
  83.         If $posTray[0] >= @DesktopWidth Then $posTray[0] = @DesktopWidth - $posTray[2]
  84.         If $posTray[1] >= @DesktopHeight Then $posTray[1] = @DesktopHeight - $posTray[3]
  85.         If $posTray[0] < 0 Then $posTray[0] = 0
  86.         If $posTray[1] < 0 Then $posTray[1] = 0
  87.         Local $y = $posTray[1]
  88.         While $y < $posTray[3] + $posTray[1]
  89.                 Local $x = $posTray[0]
  90.                 While $x < $posTray[2] + $posTray[0]
  91.                         MouseMove($x, $y, $delay)
  92.                         If $pilgrim Then Sleep(1)
  93.                         If $debug Then ConsoleWrite($x & ',' & $y & @CRLF)
  94.                         $x += 12
  95.                 WEnd
  96.                 $y += 12
  97.         WEnd
  98.         Return _SysTrayIconCount()
  99. EndFunc   ;==>_SeeYouNextYear
  100.  
  101. Func _TharHeIsGetIm()
  102.         $flag = False
  103.         Local $count = _SysTrayIconCount() ; get number of icons in tray
  104.         For $i = $count - 1 To 0 Step -1 ; step backwards through the list
  105.                 Local $handle = _SysTrayIconHandle($i) ; get handle of the icon
  106.                 Local $pid = WinGetProcess($handle) ; get process ID for ithe handle
  107.                 If $pid = -1 Then ; if no process then
  108.                         Local $iPos = _SysTrayIconPos($i) ; get icon position
  109.                         MouseMove($iPos[0], $iPos[1], $delay) ; move mouse there
  110.                         If $debug Then ConsoleWrite($iPos[0] & ',' & $iPos[1] & @CRLF)
  111.                         If _SysTrayIconCount() < $count Then ; if number of icons has reduced, set flag and exit for/next loop
  112.                                 $flag = True
  113.                                 ExitLoop
  114.                         EndIf
  115.                 EndIf
  116.         Next
  117.         If $flag Then _TharHeIsGetIm() ; if flag set call func again (a little pseudo-recursion)
  118.         MouseMove($oldPos[0], $oldPos[1], 0) ; move mouse back where it came from
  119. EndFunc   ;==>_TharHeIsGetIm
  120.  
  121. Func _NukeEmAll()
  122.         $count = _SysTrayIconCount()
  123.         For $i = $count - 1 To 0 Step -1
  124.                 $handle = _SysTrayIconHandle($i)
  125.                 $pid = WinGetProcess($handle)
  126.                 If $pid = -1 Then _SysTrayIconRemove($i)
  127.         Next
  128.  
  129.         If _OsVersionTest($VER_GREATER_EQUAL, 6, 1) Then
  130.                 $countwin7 = _SysTrayIconCount(2)
  131.                 For $i = $countwin7 - 1 To 0 Step -1
  132.                         $handle = _SysTrayIconHandle($i, 2)
  133.                         $pid = WinGetProcess($handle)
  134.                         If $pid = -1 Then _SysTrayIconRemove($i, 2)
  135.                 Next
  136.         EndIf
  137. EndFunc   ;==>_NukeEmAll
« Last Edit: May 17, 2013, 10:54:46 PM by 4wd »

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #18 on: May 11, 2013, 07:42:09 AM »
I'll have to come back to this but two quick points:
1) D4 doesn't have an Exit/Quit option in the icon menu.
2) When I originally put this batch file together using 'taskkill' on its own only shut down D4, I had to add the /F switch to shut down the other two.
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #19 on: May 12, 2013, 04:57:44 AM »
Having finally caught up with myself:

Terminator.exe - It shut down D4 and removed the icon, the Network Activity Indicator Icon also disappeared. The other two programs stayed put.
What I did get was a lot of context menus left open including one for the next icon in line that is running all the time and one for the taskbar itself?

CleanTray.exe - Only removes the icon furthest to the left.
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,473
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #20 on: May 12, 2013, 06:35:24 AM »
What I did get was a lot of context menus left open including one for the next icon in line that is running all the time and one for the taskbar itself?

Probably need to fine tune it's positioning.

Quote
CleanTray.exe - Only removes the icon furthest to the left.

cleantray /debug and attach the results thanks.

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #21 on: May 12, 2013, 07:40:24 AM »
I'm having a few problems with this.

Where, and how, do I get the debug results? :-[

I tried it in the cmd window and it wasn't recognised.

I tried adding it in the main batch file where I was running the program from and found that with /debug added it was removing different numbers of icons on each run, from 1 to all.
It also opened the USB Safely Remove pop-up saying there was nothing to disconnect.

Something I forgot to mention in my last post is that the icons no longer seem to be being rearranged. :)
I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,473
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #22 on: May 12, 2013, 08:31:00 AM »
Where, and how, do I get the debug results? :-[

I tried it in the cmd window and it wasn't recognised.

More and more I start to wonder about your system  :)

You are using cleantray 0.1.0.0, (Properties on the executable) ?

And if so, you should get something like:

2013-05-12 23_27_46-Administrator_ C__Windows_system32_cmd.exe.pngAdvice needed on AHK script

pilgrim

  • Supporting Member
  • Joined in 2008
  • **
  • Posts: 316
  • Cogito ergo ?
    • View Profile
    • Pilgrim's Page
    • Donate to Member
Re: Advice needed on AHK script
« Reply #23 on: May 12, 2013, 09:17:03 AM »
Don't worry, I just spotted the mistake, I do most of my testing on a non system drive so the CLI couldn't find the file.

I spent 25 years training to be an eccentric then I woke up one morning and realised that I'd cracked it.
I've not had to try since.

I wonder what happens if I click on thi

4wd

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 4,473
    • View Profile
    • Donate to Member
Re: Advice needed on AHK script
« Reply #24 on: May 13, 2013, 01:38:54 AM »
I just possibly realised why both the AHK and my efforts weren't quite there.

When the mouse runs over the icons Windows removes them if there's no underlying process, it then updates the following icon positions even though the display might not as yet changed.  So even though the mouse appears to run over a position where an icon is, it's not really in that position - it's been moved.

Hey, it's a theory...it explains why both the AHK script and CleanTray need to run multiple times if they're just moving the mouse around.

It also only seems to happen if the icons are situated next to each other, if they are separated by other non-orphaned icons then the slight delay as the cursor travels over them appears to be enough to allow the Notification Area to "settle" into it's new state after an icon removal.

So it all comes down to a matter of timing....

You can test this by doing CleanTray /once and CleanTray /debug /once, the /debug now adds a slight delay so you can watch the mouse move, (so I could check the movement borders), and the /once means it only runs through the cycle once.

With /debug there's enough of a delay for everything to update so that everything completes in a single cycle, (at least on my Phenom x6).

New version up there, default is it moves the mouse at fastest speed and multiple times if the number of icons reduces between runs.

Could you give /m switch a try as no matter how many times I used it, it didn't lose icon positions and it's a lot faster if there's multiple icons to remove.

Just as a matter of interest, I couldn't get the AHK script to work at all, (however it did generate some orphaned icons for me to nuke since I had to kill their tasks  ;D ).

Now I'll go back to playing with Terminator since avoiding the problem in the first place is always a better solution ;)