Timed time, day of week script not running

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
Kellyzkorner_NJ
Posts: 84
Joined: 20 Oct 2017, 18:33

Timed time, day of week script not running

22 Jul 2022, 11:19

I have this script that is basically a timer. The top part is a label. This works fine if the just time and weekday singularly are entered.

Code: Select all

#noenv
#singleinstance, ignore ;*1
#Persistent ;*2
SetWorkingDir %A_ScriptDir%
if not A_IsAdmin
	Run *RunAs "%A_ScriptFullPath%" ; (A_AhkPath is usually optional if the script has the .ahk extension.) You would typically check  first.

setbatchlines, 10ms ;*3
settimer, emptymem, 600000 ;*4
settimer, time, 500 ;*5

time:
 {
   formattime, time, , hh:mm:ss tt ;*7
   formattime, weekday, , dddd ;*8
   formattime, monthday, , dd ;*9
   formattime, month, , MM ;*10


	if (time = "07:00:00 pm" && weekday = "Friday") ;*12
    {
      goto, task1
    }
   }
I'd like to have this run at a certain time though (Windows is for some reason closing some of my scripts and programs overnight and I want to close them if open and restart or just run them in morning) and run every day of the week. So not to have to make lines for every day of the week, I tried the below.

Code: Select all

if (time = "00:12:10 pm" && weekday = "Friday") || (time = "00:12:10 pm" && weekday = "Friday") || (time = "00:12:10 pm" && weekday = "Sunday") ;  etc
	{
	goto, selectedtask
	}
This doesn't work and I don't know why. TIA.

Kelly
RussF
Posts: 1311
Joined: 05 Aug 2021, 06:36

Re: Timed time, day of week script not running

22 Jul 2022, 12:12

The first thing I would recommend is stay away from the GOTO command. It can lead to very messy and hard to maintain code.

Second, were this me, I think I would create a script for each separate task that I wanted to perform. Then create a task in Windows' Task Manager and run that script any time you want.

You have trigger times to the second. It's very possible, that if your computer is very busy with another task, that your script gets around to checking the second before and the second after, but misses the exact second you have coded. (Note, with speeds of today's PCs, this would be uncommon, but still possible.) Task Manager has a higher run priority within Windows and also has code to account for missed time checks.

There is plenty of information on how to set up a task in Task Manager, both on the web as well as within these forums.

Russ
Not_a_Robot01001
Posts: 4
Joined: 29 Jun 2017, 10:49

Re: Timed time, day of week script not running

30 Aug 2022, 11:05

I find using 24hr hours format (HH) is easier to use. I would also break up your if statement - I think the FormatTime outputs a string which typically works better as isolated statements within their own parenthesis (they can usually share an if statement).

Here is a simple timer script I use. If it's M-F, 09 AM to 5 PM, it sends F13 every 5 minutes.

Code: Select all

#NoEnv ;Avoids checking empty variables to see if they are environment variables (recommended for all new scripts).
SetTitleMatchMode, 2 ;Allows partial window title matches.
#SingleInstance, Force ;Forces only one instance of the script to exist at a time (new instances replace existing scripts).
#Persistent ;keeps script running.
;~ #NoTrayIcon; Prevents a system tray icon.

Time_Check:
;A_WDay = weekday with 1 = Sun, 2= Mon, etc.	HHmm: HH = hours, 24-hr format, mm = minutes.
FormatTime, Timestring_HHmm, ,HHmm ;Assigns current time to string variable, formatted HHmm.
if ((A_WDay >= 2) && (A_WDay <= 6) && (Timestring_HHmm >= 0900) && (Timestring_HHmm <= 1700)) ;Runs M - F, 09:00 AM - 05:00 PM.
{
	Send, {F13} ;simulates pressing F13 (phantom key).
	SetTimer, Time_Check, 300000 ;Sets timer to recheck the time after 5 minutes
}
else
	SetTimer, Time_Check, 28800000 ;Sets timer to recheck the time after 8 hours.

^+F1::ExitApp ;Control + Shift + F1 to exit script.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Rauvagol and 313 guests