link script to time

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Hema Elkady
Posts: 90
Joined: 01 Feb 2021, 03:45

link script to time

02 May 2021, 03:39

How to link script to time, for example, when it's 11:01 A.M.
Send, something
User avatar
Smile_
Posts: 858
Joined: 03 May 2020, 00:51

Re: link script to time

02 May 2021, 04:58

Code: Select all

F1::
    FormatTime, FormattedTime, % A_Now, hh:mm:ss tt
    Send, % FormattedTime
Return
User avatar
mikeyww
Posts: 26951
Joined: 09 Sep 2014, 18:38

Re: link script to time

02 May 2021, 05:16

You can use the Windows Task Scheduler to run a script at a particular time.

Program = full path to AutoHotkey.exe
Arguments = full path to your script file
Rohwedder
Posts: 7648
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: link script to time

02 May 2021, 05:21

Hallo,
If something should be sent at several specific times of the day:

Code: Select all

#Persistent
DoIt:
IF DoIt
{
    FormatTime, FormattedTime, % A_Now, hh:mm:ss tt
    Send, % FormattedTime
}
FormatTime, Now,, HHmmss
For all, Time in [0908,1101,1345,1540] ;HHmm
{
    IF (Now > Time .= "00") Or (Time = OldTime)
        Continue
    DoIt := "20010101" OldTime := Time
    DoIt -= "20010101" Now, Seconds
    SetTimer, DoIt,% -Max(DoIt,1)*1000
    Break
}
Return
teadrinker
Posts: 4331
Joined: 29 Mar 2015, 09:41
Contact:

Re: link script to time

02 May 2021, 05:58

@Rohwedder
Try this:

Code: Select all

#Persistent
DoIt:
IF DoIt
{
    FormatTime, FormattedTime, % A_Now, hh:mm:ss tt
    Send, % FormattedTime
}
FormatTime, Now,, HHmmss
For all, Time in [0001] ;HHmm
{
    IF (Now > Time .= "00") Or (Time = OldTime)
        Continue
    MsgBox, % DoIt := "20010101" OldTime := Time
    DoIt -= "20010101" Now, Seconds
    MsgBox, % DoIt
    SetTimer, DoIt,% -Max(DoIt,1)*1000
    Break
}
MsgBox, Wtf?
Return
Rohwedder
Posts: 7648
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: link script to time

02 May 2021, 09:40

Then perhaps?:

Code: Select all

#Persistent
DoIt:
IF DoIt
{
	FormatTime, FormattedTime,% A_Now, hh:mm:ss tt
	Send, % FormattedTime
}
FormatTime, Now,, HHmmss
Loop
{
	Day := A_Index
	For all, Time in [0908,1101,1345,1540] ;HHmm
	{
		DoIt := "2001010" Day Format("{:04}", Time)
		DoIt -= "20010101" Now, Seconds
		IF DoIt > 1
			Break, 2
	}
}
SetTimer, DoIt,% -DoIt*1000
Return
Hema Elkady
Posts: 90
Joined: 01 Feb 2021, 03:45

Re: link script to time

02 May 2021, 10:48

Smile_ wrote:
02 May 2021, 04:58

Code: Select all

F1::
    FormatTime, FormattedTime, % A_Now, hh:mm:ss tt
    Send, % FormattedTime
Return
I don't want it Send, % FormattedTime
but I want if FormattedTime = 11:40 P.m.
send, {Enter}
Rohwedder
Posts: 7648
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: link script to time

02 May 2021, 10:57

Try:

Code: Select all

#Persistent
DoIt:
IF DoIt
	Send, {Enter}
FormatTime, Now,, HHmmss
Loop
{
	Day := A_Index
	For all, Time in [2340] ; HHmm, 2340 = 11:40 P.m.
	{
		DoIt := "2001010" Day Format("{:04}", Time)
		DoIt -= "20010101" Now, Seconds
		IF DoIt > 1
			Break, 2
	}
}
SetTimer, DoIt,% -DoIt*1000
Return
or:

Code: Select all

#Persistent
DoIt:
SetTimer, Doit, 1000
IF (A_Hour A_Min <> "2340") ;HHmm, 2340 = 11:40 P.m.
	Return
Send, {Enter}
SetTimer, Doit, 60050
Return
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

Re: link script to time

02 May 2021, 11:12

Hema Elkady wrote:
02 May 2021, 10:48
I don't want it Send, % FormattedTime
but I want if FormattedTime = 11:40 P.m.
send, {Enter}

If you're asking how to execute a script at a specific time automatically, Rohwedder's most recent reply is the best answer.
Rohwedder wrote:
02 May 2021, 10:57
Try:

Code: Select all

#Persistent
DoIt:
SetTimer, Doit, 1000
IF (A_Hour A_Min <> "2340") ;HHmm, 2340 = 11:40 P.m.
	Return
Send, {Enter}
SetTimer, Doit, 60050
Return
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

Re: link script to time

06 May 2021, 09:15

Rohwedder wrote:
02 May 2021, 10:57

Code: Select all

#Persistent
DoIt:
SetTimer, Doit, 1000
IF (A_Hour A_Min <> "2340") ;HHmm, 2340 = 11:40 P.m.
	Return
Send, {Enter}
SetTimer, Doit, 60050
Return
Hi Rohwedder, I have a similar question. I have a script that I would like to launch every Thursday at 10:30 am. Using your example, I am able to launch it at the desired time.

Is there a way to make it launch on Thursdays only?
Rohwedder
Posts: 7648
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: link script to time

06 May 2021, 09:24

Then perhaps:

Code: Select all

#Persistent
DoIt:
SetTimer, Doit, 1000
IF (A_WDay A_Hour A_Min <> "51030") ;WdayHHmm, Thursday at 10:30 am
	Return ;Wday = Current 1-digit day of the week (1-7). 1 is Sunday 
Send, {Enter}
SetTimer, Doit, 60050
Return
But, there are definitely better methods!
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

Re: link script to time

06 May 2021, 09:34

Rohwedder wrote:
06 May 2021, 09:24
Then perhaps:

Code: Select all

#Persistent
DoIt:
SetTimer, Doit, 1000
IF (A_WDay A_Hour A_Min <> "51030") ;WdayHHmm, Thursday at 10:30 am
	Return ;Wday = Current 1-digit day of the week (1-7). 1 is Sunday 
Send, {Enter}
SetTimer, Doit, 60050
Return
But, there are definitely better methods!
There might be better methods but for my simple home use, this will do just fine. Thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, OrangeCat and 185 guests