stiv Posted September 28, 2021 Share Posted September 28, 2021 Good morning colleagues from Autoit, It is possible to program in autoit, a script that runs every day at the same time. example every Friday at 9 a.m. without using windows task scheduler. Thank you Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted September 28, 2021 Moderators Share Posted September 28, 2021 stiv, Of course. You can use the @Date and @Time macros to specify the point in time you require. Then use a series of If statements in a loop to check when you are getting close - and speeding up the loop as you do so. There are other ways too, but that is a good way to start as it gives yo lots of practice in coding. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
stiv Posted September 29, 2021 Author Share Posted September 29, 2021 @Melba23 THANK YOU could you give me a basic example. please Link to comment Share on other sites More sharing options...
Zedna Posted September 29, 2021 Share Posted September 29, 2021 Every friday at 9:00 While 1 If @WDAY = 6 And @HOUR = 9 And @MIN = 0 Then DoMyAction() Sleep(60001) ; 1 minute WEnd Func DoMyAction() ;... EndFunc Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
robertocm Posted September 29, 2021 Share Posted September 29, 2021 (edited) two minutes before 9:00, checking user inactive #include <Date.au3> #include <Timers.au3> Global $Year, $Mon, $Day $Year = @YEAR $Mon = @MON $Day = @MDAY While 1 ;use infinite loop since ExitLoop will get called If _DateDiff('n', _NowCalc(), $Year & "/" & $Mon & "/" & $Day & " 09:00:00") < 2 Then ;https://stackoverflow.com/questions/3867584/autoit-how-to-get-system-idle-time-or-if-screensaver-is-active If _Timer_GetIdleTime() > 30000 Then ExitLoop EndIf EndIf Sleep(60001) ; 1 minute WEnd ;Similar ;Do ;Sleep(60001) ;Until _DateDiff('n', _NowCalc(), $Year & "/" & $Mon & "/" & $Day & " 09:00:00") < 2 ConsoleWrite("something" & @CRLF) Edited September 29, 2021 by robertocm Link to comment Share on other sites More sharing options...
JockoDundee Posted September 30, 2021 Share Posted September 30, 2021 On 9/29/2021 at 9:27 AM, Zedna said: Every friday at 9:00 Of course there’s a remote chance of inadvertent execution around 9:59:59.999 when @HOUR still = 9, yet @MIN has just flipped to 0 Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Zedna Posted September 30, 2021 Share Posted September 30, 2021 (edited) @JockoDundee That's why my Sleep() is Sleep(60001) and not Sleep(60000) --> to avoid execution more than once at one minute But YES you are right, my script is very simple but not as acurate. Edited September 30, 2021 by Zedna Resources UDF ResourcesEx UDF AutoIt Forum Search Link to comment Share on other sites More sharing options...
Moderators Solution Melba23 Posted September 30, 2021 Moderators Solution Share Posted September 30, 2021 Hi, The Devs were discussing this a while ago and came up with two possible workarounds for the standard AutoIt include functions to prevent this scenario. Here are the options for _NowCalc: Func _NowCalc_Atomic() Local $tStamp = _Date_Time_GetLocalTime() Return DllStructGetData($tStamp, "Year") & "/" & _ StringFormat("%02s", DllStructGetData($tStamp, "Month")) & "/" & _ StringFormat("%02s", DllStructGetData($tStamp, "Day")) & " " & _ StringFormat("%02s", DllStructGetData($tStamp, "Hour")) & ":" & _ StringFormat("%02s", DllStructGetData($tStamp, "Minute")) & ":" & _ StringFormat("%02s", DllStructGetData($tStamp, "Second")) EndFunc ;==>_NowCalc_Atomic Func _NowCalc_Check() Local $sRet, $sCheck Do $sCheck = @SEC $sRet = @YEAR & "/" & @MON & "/" & @MDAY & " " & @HOUR & ":" & @MIN & ":" & @SEC Until @SEC = $sCheck Return $sRet EndFunc ;==>_NowCalc_Check The first of these options will be incorporated for all such functions in the next AutoIt release - and please, please do not ask me when that will be! M23 HurleyShanabarger and stiv 2 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
JockoDundee Posted September 30, 2021 Share Posted September 30, 2021 (edited) 4 hours ago, Zedna said: But YES you are right, my script is very simple but not as acurate. Just to be clear, I think your script is accurate, except for once in a blue moon it fires ~1 hour after the last time. The Sleep(60001) does not prevent it since it happens 59 minutes after the sleep is expired. How often does it glitch? I wrote this to test: #include <Date.au3> Local $sNow, $sThen, $iCalls=0, $htimer=TimerInit() Do $sThen=$sNow $sNow=_NowCalc() $iCalls+=1 Until $sNow<$sThen ConsoleWrite("Time jumped from "& $sNow &" to "& $sThen &@CRLF) ConsoleWrite("Run Time: "& Round(TimerDiff($htimer)/1000,3) &@CRLF) ConsoleWrite("Calls Made: "& $iCalls &@CRLF) This uses the current _NowCalc() function which returns a concatenation of date macros, and suffers from the same rollover glitch, except at the @SEC level. But it’s rare - below it happened 1 time in 13 million tests. So your script might have gone 10 million days without an error. Time jumped from 2021/05/20 21:01:00 to 2021/05/20 21:01:59 Run Time: 50.323 Calls Made: 13602962 Edited September 30, 2021 by JockoDundee Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now