DonationCoder.com Forum

Main Area and Open Discussion => General Software Discussion => Topic started by: nudone on April 29, 2010, 08:45 AM

Title: refresh all open browsers automatically?
Post by: nudone on April 29, 2010, 08:45 AM
anyone know of a little util that will automatically refresh ALL browsers that are open?

when i say "automatically" i mean, by pressing a single key or button and then IE, FireFox, Safari, Chome, Opera, etc. refresh the page they are on (or the main tab that's selected).

this has got to be an old idea so there ought to be something out there - not that i can find anything.
Title: Re: refresh all open browsers automatically?
Post by: skwire on April 29, 2010, 09:13 AM
This wouldn't take much in AHK.  Give me a minute.
Title: Re: refresh all open browsers automatically?
Post by: skwire on April 29, 2010, 09:34 AM
Tested on my computer running WinXP SP2 and with the following browsers:

Firefox
Internet Explorer
Maxthon
Opera
Safari
Chrome

Code: AutoIt [Select]
  1. WinGet, myList, List
  2. Loop, % myList
  3. {
  4.     myID := myList%A_Index%
  5.     WinGetTitle, myTitle, % "ahk_id " . myID
  6.     WinGetClass, myClass, % "ahk_id " . myID
  7.  
  8.     If myTitle contains Firefox,Chrome,Maxthon ; These accept remote keysends directly.
  9.     {
  10.         ControlSend, , {F5}, % "ahk_id " . myID
  11.     }
  12.     Else If myTitle contains Opera,Internet Explorer ; These have to be focused first.
  13.     {
  14.         WinActivate, % "ahk_id " . myID
  15.         ControlSend, , {Ctrl down}r{Ctrl up}, % "ahk_id " . myID
  16.     }
  17.     Else If myClass contains {1C03B488-D53B-4a81-97F8-754559640193} ; Safari.
  18.     {
  19.         WinActivate, % "ahk_id " . myID
  20.         ControlSend, , {F5}, % "ahk_id " . myID
  21.     }
  22. }
Title: Re: refresh all open browsers automatically?
Post by: nudone on April 29, 2010, 10:17 AM
thanks for giving it a shot, skwire but it doesn't seem to be refreshing more than a single browser at a time - i think it may have done two though.

i'm using vista so maybe that's the problem.

interestingly, Internet Explorer refreshes without being focussed - sometimes. the two that refreshed together were Chrome and IE.

Firefox doesn't appear to want to play and neither does Maxthon.

if this all sounds inexplicable then it might be best to leave it alone - if it's a vista thing then i'm sort of stuck.

oh, one other thing - does it matter if i have lots of non browser windows open at the same time? i should have mentioned that in the first place. sorry.
Title: Re: refresh all open browsers automatically?
Post by: skwire on April 29, 2010, 06:09 PM
i'm using vista so maybe that's the problem.

Could be...but I don't see why that would make such a huge difference in this case.

oh, one other thing - does it matter if i have lots of non browser windows open at the same time? i should have mentioned that in the first place. sorry.

No, that shouldn't matter.  The code:

1) Scans through all open processes.
2) Gets their window title and class.
3) Matches against a few lists.
4) Sends an F5 (Ctrl-R in some cases) keystroke to the parent window.
Title: Re: refresh all open browsers automatically?
Post by: nudone on April 30, 2010, 03:29 AM
right. that's how i thought it was working - i'm trying to think of what could be stopping it.

i wondered if using multi-monitors would be a problem but it is refreshing IE on a 2nd screen and Chrome on the main screen - so no problem there.

would it make a difference if the process performed slower?

i've 3 other autohotkey scripts running at the same time - could these be challenging this browser refresh script in some way?
Title: Re: refresh all open browsers automatically?
Post by: skwire on April 30, 2010, 03:32 AM
would it make a difference if the process performed slower?

No, it shouldn't.

i've 3 other autohotkey scripts running at the same time - could these be challenging this browser refresh script in some way?

Nope.  However, if you don't mind, I could re-write it so that each window is focused first and then dealt with.  Is this acceptable?
Title: Re: refresh all open browsers automatically?
Post by: nudone on April 30, 2010, 04:02 AM
Nope.  However, if you don't mind, I could re-write it so that each window is focused first and then dealt with.  Is this acceptable?

ooh, that's a good idea. please do.
Title: Re: refresh all open browsers automatically?
Post by: skwire on April 30, 2010, 04:22 AM
Try this:

Code: AutoIt [Select]
  1. WinGet, myList, List
  2. Loop, % myList
  3. {
  4.     myID := myList%A_Index%
  5.     WinGetTitle, myTitle, % "ahk_id " . myID
  6.     WinGetClass, myClass, % "ahk_id " . myID
  7.  
  8.     If myTitle contains Firefox,Chrome,Maxthon,Opera,Internet Explorer
  9.     {
  10.         WinActivate, % "ahk_id " . myID
  11.         WinWaitActive, % "ahk_id " . myID
  12.         SendInput, {Ctrl down}r{Ctrl up}
  13.         Sleep, 250
  14.         ; ControlSend, , {Ctrl down}r{Ctrl up}, % "ahk_id " . myID
  15.         ; ControlSend, , {F5}, % "ahk_id " . myID
  16.         ; SendInput, {F5}
  17.     }
  18.     Else If myClass contains {1C03B488-D53B-4a81-97F8-754559640193} ; Safari.
  19.     {
  20.         WinActivate, % "ahk_id " . myID
  21.         WinWaitActive, % "ahk_id " . myID
  22.         SendInput, {Ctrl down}r{Ctrl up}
  23.         Sleep, 250
  24.         ; ControlSend, , {Ctrl down}r{Ctrl up}, % "ahk_id " . myID
  25.         ; ControlSend, , {F5}, % "ahk_id " . myID
  26.         ; SendInput, {F5}
  27.     }
  28. }
Title: Re: refresh all open browsers automatically?
Post by: nudone on April 30, 2010, 05:29 AM
excellent. it now appears to work (it got stuck a couple of times but i can't say why).

i've just changed the SendInput to F5 as Maxthon didn't want to respond (even after making sure that ctrl+R did work for it).

perhaps this should be included on Skwire Empire - i think it's a really helpful web development util. i still don't understand why there hasn't been something like this around for years.

i'll send some DC credits later - just waiting for them to go into my account first.

thanks very much for this, skwire.
Title: Re: refresh all open browsers automatically?
Post by: skwire on April 30, 2010, 06:28 AM
excellent. it now appears to work (it got stuck a couple of times but i can't say why).
i've just changed the SendInput to F5 as Maxthon didn't want to respond (even after making sure that ctrl+R did work for it).

Who knows?   :D  That's how these scriptlets go sometimes.  You could play with the sleep value a bit to see if that helps.

perhaps this should be included on Skwire Empire - i think it's a really helpful web development util. i still don't understand why there hasn't been something like this around for years.

*shrug* Honestly, that above code  is very simple and could be set as a hotkey in your main AHK script (if you use one).  Bits like this really show off how flexible and powerful AHK is as a language.

i'll send some DC credits later - just waiting for them to go into my account first.
thanks very much for this, skwire.

You are most welcome.  Happy to help.   :)
Title: Re: refresh all open browsers automatically?
Post by: nudone on April 30, 2010, 06:43 AM
i've been wondering about combining all of the autohotkey scripts into one single script - something i'll have to investigate later.

if you don't mind, maybe i'll try and modify the browser refresh script into a little tray app - just with a menu for selecting browsers or something. it would give me something to play with and learn autohotkey.
Title: Re: refresh all open browsers automatically?
Post by: skwire on April 30, 2010, 06:52 AM
if you don't mind, maybe i'll try and modify the browser refresh script into a little tray app - just with a menu for selecting browsers or something. it would give me something to play with and learn autohotkey.

By all means, please do.  I'm happy to help if you get stuck, too.