Timed schedule for multiple scripts

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
nairnmonster3981
Posts: 10
Joined: 27 Jun 2021, 07:10

Timed schedule for multiple scripts

Post by nairnmonster3981 » 27 Jun 2021, 07:17

Hi there,

I've been trying my best to get this working.

I have two scripts to move the mouse and click. I need them to happen 2 times per hour for each one. I can get a single timer schedule working. But trying to add more I'm out of my depth. Been going though loads in the hope of sorting it or at least have someone point me right.

Here is what I have already.

As an example, I need 0 to run on the hour and half past and 5 to run 5 past the hour and 35 for 10 hours. I just can't workout where I am going wrong.

Any help or direction would be amazing.

Thanks

Code: Select all

#Persistent    ; Script by BoBo
SetTimer, Chronos, 500
Return

Escape::
ExitApp
Return

Chronos:
FormatTime, TimeToMeet,,HHmm
If TimeToMeet = 1300 ; If you wanted the script to start at 7 am put change 1006 to 700
{
   Run "C:\Users\user\OneDrive - work\Documents\Autohotkey\0.ahk"
}

FormatTime, TimeToMeet,,HHmm
If TimeToMeet = 1305 ;
{
   Run "C:\Users\user\OneDrive - work\Documents\Autohotkey\5.ahk"
  ExitApp
}
Return
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Timed schedule for multiple scripts

Post by mikeyww » 27 Jun 2021, 09:27

One easy way to run scripts at specific times is to set the Windows Task Scheduler to run your scripts. Use the full path to AutoHotkey.exe as the program, and the full path to your script as the argument.

nairnmonster3981
Posts: 10
Joined: 27 Jun 2021, 07:10

Re: Timed schedule for multiple scripts

Post by nairnmonster3981 » 27 Jun 2021, 09:36

mikeyww wrote:
27 Jun 2021, 09:27
One easy way to run scripts at specific times is to set the Windows Task Scheduler to run your scripts. Use the full path to AutoHotkey.exe as the program, and the full path to your script as the argument.
Thanks for the reply, I did think of that. But would that not mean setting up 20 different schedules for all the times. I need to be able to pause all at the same time.

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Timed schedule for multiple scripts

Post by mikeyww » 27 Jun 2021, 11:12

Could be. Here is another way.

Code: Select all

#Persistent
SetTimer, Chronos, 60000
SetTimer, Stop, % -1000 * 60 * 60 * 10
SoundBeep, 1500
Chronos:
If A_Min in 00,05,30,35
 Run, % StrReplace(A_MyDocuments, "Documents") "OneDrive - work\Documents\Autohotkey\" SubStr(A_Min, 0) ".ahk"
Return
Stop:
SetTimer, Chronos, Off
SoundBeep, 1000
Return
Last edited by mikeyww on 27 Jun 2021, 11:22, edited 2 times in total.

nairnmonster3981
Posts: 10
Joined: 27 Jun 2021, 07:10

Re: Timed schedule for multiple scripts

Post by nairnmonster3981 » 27 Jun 2021, 11:18

mikeyww wrote:
27 Jun 2021, 11:12
Could be. Here is another way.
Thanks so much for the help.

How can I go learning this myself, I very much appreciate the help but really want to be learning this myself to help others.

The tutorials are good but I struggle to take it to the next level.

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Timed schedule for multiple scripts

Post by mikeyww » 27 Jun 2021, 11:25

Here is a simplification if easier to follow.

Code: Select all

#Persistent
SetTimer, Chronos, 60000
SetTimer, Stop, % -1000 * 60 * 60 * 10
SoundBeep, 1500
Chronos:
If A_Min in 00,30
 Run "C:\Users\user\OneDrive - work\Documents\Autohotkey\0.ahk"
If A_Min in 05,35
 Run "C:\Users\user\OneDrive - work\Documents\Autohotkey\5.ahk"
Return
Stop:
SetTimer, Chronos, Off
SoundBeep, 1000
Return
I wonder if you have looked at the AHK documentation. It has many examples. A_Min is the two-digit minute (noted there). Here is the If... in syntax. Here is info about SetTimer. Does that help?

The "Stop" turns off your timer. When the timer interval is negative, the timer will run only once. In this case, then, the timer that stops the running timer is executed once after ten hours (specified in milliseconds).

If one minute is the unit of time that you want to check for running your program, then you want a timer interval of one minute, which is 60 seconds or 60000 milliseconds.

nairnmonster3981
Posts: 10
Joined: 27 Jun 2021, 07:10

Re: Timed schedule for multiple scripts

Post by nairnmonster3981 » 27 Jun 2021, 11:47

mikeyww wrote:
27 Jun 2021, 11:25
Here is a simplification if easier to follow.

Code: Select all

#Persistent
SetTimer, Chronos, 60000
SetTimer, Stop, % -1000 * 60 * 60 * 10
SoundBeep, 1500
Chronos:
If A_Min in 00,30
 Run "C:\Users\user\OneDrive - work\Documents\Autohotkey\0.ahk"
If A_Min in 05,35
 Run "C:\Users\user\OneDrive - work\Documents\Autohotkey\5.ahk"
Return
Stop:
SetTimer, Chronos, Off
SoundBeep, 1000
Return
I wonder if you have looked at the AHK documentation. It has many examples. A_Min is the two-digit minute (noted there). Here is the If... in syntax. Here is info about SetTimer. Does that help?

The "Stop" turns off your timer. When the timer interval is negative, the timer will run only once. In this case, then, the timer that stops the running timer is executed once after ten hours (specified in milliseconds).

If one minute is the unit of time that you want to check for running your program, then you want a timer interval of one minute, which is 60 seconds or 60000 milliseconds.
Yeah that makes more sense, I'm going take a look at the documentation a lot more. Think I just need to take some time.

nairnmonster3981
Posts: 10
Joined: 27 Jun 2021, 07:10

Re: Timed schedule for multiple scripts

Post by nairnmonster3981 » 27 Jun 2021, 12:17

That simplified script is working. But I can't get my head around how it works.

Think I just need to spend time reading and playing more. I didn't know the possibilities of AHK were pretty much limitless.

Thanks again for the help. Couldn't have done it without your input and time.

User avatar
mikeyww
Posts: 27372
Joined: 09 Sep 2014, 18:38

Re: Timed schedule for multiple scripts

Post by mikeyww » 27 Jun 2021, 12:29

You are welcome. Chronos runs every minute. If the minute is 0 or 30, it runs the first script. If the minute is 5 or 35, it runs the second script. After 10 hours, the timer stops.

Post Reply

Return to “Ask for Help (v1)”