Jump to content

schedule execution of date and time in autoit


stiv
 Share

Go to solution Solved by Melba23,

Recommended Posts

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by robertocm
Link to comment
Share on other sites

  • Moderators
  • Solution

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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 by JockoDundee

Code hard, but don’t hard code...

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...