Unable to refresh in background Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
Posts: 518
Joined: 02 Aug 2020, 22:44

Unable to refresh in background

14 Aug 2020, 15:15

Okay all... Thank you so much for the help I have received. This place is great.

The code I have below will refresh the page, as long as I have the page open with the title of the page. I need it to refresh whether I"m looking at another page or writing an email. Is there a way to do this?

Code: Select all

IfWinExist, Ask For Help - AutoHotkey Community - Google Chrome
WinGetClass, class
If class = Chrome_WidgetWin_1

Sleep 5000
Send {F5}
MsgBox Window cannot be found
Posts: 1147
Joined: 06 Mar 2017, 16:18
GitHub: AAhkUser
Location: France

Re: Unable to refresh in background  Topic is solved

15 Aug 2020, 08:36

Hi Epialis,

If you're looking at the other page or writing the email from another browser (e.g. firefox) something like the following might work as a possible solution:

Code: Select all

; #Warn
SendMode Input
SetWorkingDir %A_ScriptDir%
#SingleInstance force

; note: requires acc.ahk (https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/master/Libraries/Acc.ahk)
#Include %A_ScriptDir%\Acc.ahk

title := "AutoHotkey ahk_exe chrome.exe"
while (WinExist(title))
	WinWaitClose % title
run chrome.exe --new-window https://www.autohotkey.com ; open chrome in a new window
WinWait % title ; waits until the specified window exists and updates the Last Found Window if a matching window comes into existence
chromeID := WinExist() ; store the Last Found Window's Unique ID (HWND)

path := ""
; acc viewer (https://github.com/Drugoy/Autohotkey-scripts-.ahk/blob/16b3c57e449d08231c1753703b187ae95e4820c1/DevTools/AccViewer.ahk) allowed me to retrieve this path, which is the
; path to the chrome's own built-in refresh button, located on the left side of its adress bar
acc := Acc_Get("Object", path,, "ahk_id " . chromeID) ; retrieve the refresh button as an accessible object
seconds := 5
SetTimer, refresh, % seconds * 1000 ; SetTime can be used to cause a subroutine to be launched automatically and repeatedly at a specified time interval (here every 5000ms)

	if not (WinExist("ahk_id " . chromeID)) {
		SetTimer,, Off
	; otherwise...
	acc.accDoDefaultAction(0) ; perform the object's default action

I would generally recommend against the use of such automation. But maybe you have a good reason to do so. In any case, if this is not your web site, don't forget that such a refresh, when using unreasonable delays, can result in harm (among others, to users of the web site and to those who produced it as service provider).

my scripts
Posts: 518
Joined: 02 Aug 2020, 22:44

Re: Unable to refresh in background

15 Aug 2020, 12:34


Does the trick, thank you kindly. :)

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], mikagenic, TAC109, takenbythedesert and 42 guests