DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: refresh all open browsers automatically?  (Read 13,566 times)

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • Cody Award
refresh all open browsers automatically?
« on: April 29, 2010, 01:45 PM »
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.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: refresh all open browsers automatically?
« Reply #1 on: April 29, 2010, 02:13 PM »
This wouldn't take much in AHK.  Give me a minute.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: refresh all open browsers automatically?
« Reply #2 on: April 29, 2010, 02:34 PM »
Tested on my computer running WinXP SP2 and with the following browsers:

Firefox
Internet Explorer
Maxthon
Opera
Safari
Chrome

Code: (autoit)
WinGet, myList, List
Loop, % myList
{
    myID := myList%A_Index%
    WinGetTitle, myTitle, % "ahk_id " . myID
    WinGetClass, myClass, % "ahk_id " . myID

    If myTitle contains Firefox,Chrome,Maxthon ; These accept remote keysends directly.
    {
        ControlSend, , {F5}, % "ahk_id " . myID
    }
    Else If myTitle contains Opera,Internet Explorer ; These have to be focused first.
    {
        WinActivate, % "ahk_id " . myID
        ControlSend, , {Ctrl down}r{Ctrl up}, % "ahk_id " . myID
    }
    Else If myClass contains {1C03B488-D53B-4a81-97F8-754559640193} ; Safari.
    {
        WinActivate, % "ahk_id " . myID
        ControlSend, , {F5}, % "ahk_id " . myID
    }
}

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • Cody Award
Re: refresh all open browsers automatically?
« Reply #3 on: April 29, 2010, 03:17 PM »
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.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: refresh all open browsers automatically?
« Reply #4 on: April 29, 2010, 11: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.

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • Cody Award
Re: refresh all open browsers automatically?
« Reply #5 on: April 30, 2010, 08: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?

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: refresh all open browsers automatically?
« Reply #6 on: April 30, 2010, 08: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?

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • Cody Award
Re: refresh all open browsers automatically?
« Reply #7 on: April 30, 2010, 09: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.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: refresh all open browsers automatically?
« Reply #8 on: April 30, 2010, 09:22 AM »
Try this:

Code: (autoit)
WinGet, myList, List
Loop, % myList
{
    myID := myList%A_Index%
    WinGetTitle, myTitle, % "ahk_id " . myID
    WinGetClass, myClass, % "ahk_id " . myID

    If myTitle contains Firefox,Chrome,Maxthon,Opera,Internet Explorer
    {
        WinActivate, % "ahk_id " . myID
        WinWaitActive, % "ahk_id " . myID
        SendInput, {Ctrl down}r{Ctrl up}
        Sleep, 250
        ; ControlSend, , {Ctrl down}r{Ctrl up}, % "ahk_id " . myID
        ; ControlSend, , {F5}, % "ahk_id " . myID
        ; SendInput, {F5}
    }
    Else If myClass contains {1C03B488-D53B-4a81-97F8-754559640193} ; Safari.
    {
        WinActivate, % "ahk_id " . myID
        WinWaitActive, % "ahk_id " . myID
        SendInput, {Ctrl down}r{Ctrl up}
        Sleep, 250
        ; ControlSend, , {Ctrl down}r{Ctrl up}, % "ahk_id " . myID
        ; ControlSend, , {F5}, % "ahk_id " . myID
        ; SendInput, {F5}
    }
}

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • Cody Award
Re: refresh all open browsers automatically?
« Reply #9 on: April 30, 2010, 10: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.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: refresh all open browsers automatically?
« Reply #10 on: April 30, 2010, 11: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.  :)

nudone

  • Cody's Creator
  • Columnist
  • Joined in 2005
  • ***
  • Posts: 4,119
    • Cody Award
Re: refresh all open browsers automatically?
« Reply #11 on: April 30, 2010, 11: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.

skwire

  • I eat Coding Snacks for breakfast...
  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,297
    • Participated in NANY Challenge Seventeen Times
    • Coding Snacks
    • Superboy Coder
    • Cody Award
    • Volunteers/Staff
    • Gathering Badge
Re: refresh all open browsers automatically?
« Reply #12 on: April 30, 2010, 11: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.

Original address: https://www.donationcoder.com/forum/index.php?topic=22579.0