How to repeat a script every 3 hours

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

How to repeat a script every 3 hours

02 Apr 2021, 10:13

I need to login to a website every 3 hours and do some stuff. I've got the entire script written out but I can't figure out how to make it repeat every 3 hours. Is this the right way?

Code: Select all

#Persistent
SetTimer, LoginDoStuff, 10800000
Return

LoginDoStuff:
script goes here
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to repeat a script every 3 hours

02 Apr 2021, 10:19

Yes. Remember Return at the end of your timed routine.

If you want the first iteration to occur immediately, then you can remove your initial Return.
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

Re: How to repeat a script every 3 hours

02 Apr 2021, 10:35

OK thanks.

I have a related question: do i always have to express the time in milliseconds? I had to do some quick calculations to figure out how many seconds in 3 hour period expressed as miliseconds. It wasn't at all difficult but it would have been more convenient to just type in 180 (for 180 minutes). I assumed that AHK would interpret that as 180 miliseconds so I used a value of 10800000.

EDIT: Yes I do indeed want the first iteration to fire off immediately. Based on your reply, this should be the correct script, no?

Code: Select all

#Persistent
SetTimer, LoginDoStuff, 10800000

LoginDoStuff:
script goes here
Return
Last edited by M4verick on 02 Apr 2021, 10:39, edited 1 time in total.
HotKeyIt
Posts: 2364
Joined: 29 Sep 2013, 18:35
Contact:

Re: How to repeat a script every 3 hours

02 Apr 2021, 10:37

1000 ms = 1 Sec
60 Sec = 1 Min
60 Min = 1 Hour

Code: Select all

SetTimer, LoginDoStuff, % 3*60*60*1000

Code: Select all

hour:=60*min:=60*sec:=1000
SetTimer, LoginDoStuff, % 3*hour
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

Re: How to repeat a script every 3 hours

02 Apr 2021, 10:41

@HotKeyIt Cool, I learned something new today! Thanks.

What does the % sign do by the way?
User avatar
mikeyww
Posts: 27366
Joined: 09 Sep 2014, 18:38

Re: How to repeat a script every 3 hours

02 Apr 2021, 11:06

Since AHK commands use literal strings, if you want to use an expression instead, the % is usually needed as a marker of a forced expression.

Explained: Forced expressions

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rohwedder, Vanda_a and 367 guests