timer to run only allowed to run at a certain time Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
chubbychub
Posts: 43
Joined: 23 Feb 2017, 00:45

timer to run only allowed to run at a certain time

14 Jan 2020, 04:55

i want to set a timer, let say a user opens up a script (by accident or intentionally) , this script will check if its between 12:00am and 1:59 am, anytime other time it will exit unless its 12:00 am to 1:59 am.
i am not sure how to correct this code:

Code: Select all

 exitTime = 1:59
setTimer, watchTime, 6000


watchTime:
  if ( a_hour  a_min >= exitTime )
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: timer to run only allowed to run at a certain time

14 Jan 2020, 05:05

You should use the Scheduler feature of windows, this will simplify the problem, you just need to focus on your working code instead of processing time.
chubbychub
Posts: 43
Joined: 23 Feb 2017, 00:45

Re: timer to run only allowed to run at a certain time

14 Jan 2020, 05:11

i have the task scheduler running it, but sometimes the script gets closed accidentally or open accidentally (because of various reasons) so this is the only way i can make sure its allowed to run. (aside from that i would like to learn and while doing it solve a problem)
Rohwedder
Posts: 7627
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: timer to run only allowed to run at a certain time  Topic is solved

14 Jan 2020, 06:34

Hallo,
try:

Code: Select all

FormatTime, Today,, yyyyMMdd
Start := Today 101002 ;10:10:02 am
End := Today 161013 ;04:10:13 pm
IF A_Now between %Start% and %End%
	MsgBox, Now is between Start and End
dieissonc
Posts: 17
Joined: 29 Apr 2019, 08:40

Re: timer to run only allowed to run at a certain time

14 Jan 2020, 09:57

Code: Select all

if(A_Hour >= 2 and A_Hour <= 23)
	ExitApp
or

Code: Select all

if	A_Hour BETWEEN	2	and	23
	ExitApp
chubbychub
Posts: 43
Joined: 23 Feb 2017, 00:45

Re: timer to run only allowed to run at a certain time

14 Jan 2020, 10:11

thank you all for the replies,
what about if its at 1:58am? i would like to learn the minute syntax "a_min"
i think the simplest one is from dieissonc

Code: Select all

if(A_Hour >= 2 and A_Hour <= 23)
	ExitApp
but how do i add minutes there? so i know the syntax for future?
chubbychub
Posts: 43
Joined: 23 Feb 2017, 00:45

Re: timer to run only allowed to run at a certain time

14 Jan 2020, 12:10

is it like this?

Code: Select all

if(A_Hour A_min >= 903 and A_Hour A_min <= 907)
User avatar
telanx
Posts: 68
Joined: 10 Jan 2020, 14:31

Re: timer to run only allowed to run at a certain time

14 Jan 2020, 12:55

This should be what you want. :ugeek:

Code: Select all

if (A_Hour >= 0 and A_Hour <= 1) {
    if (A_Min >= 0 and A_Min <= 59)
        if (A_Sec >= 0 and A_Sec <= 59)
            msgbox CurrentTime:%A_Hour%:%A_Min%:%A_Sec%
            msgbox You want function code
} else {
    ExitApp
}
return
User avatar
flyingDman
Posts: 2817
Joined: 29 Sep 2013, 19:01

Re: timer to run only allowed to run at a certain time

14 Jan 2020, 16:13

try:

Code: Select all

FormatTime, oVar,,Hmm
if (oVar<159)
	msgbox run!
14.3 & 1.3.7
chubbychub
Posts: 43
Joined: 23 Feb 2017, 00:45

Re: timer to run only allowed to run at a certain time

14 Jan 2020, 19:58

yes, thank you all! flyingDman, telanx, dieissonc , i got it now! thanks for all the replies in my journey of learning

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, Joey5, RandomBoy, wpulford and 383 guests