Jump to content
Sign in to follow this  
Diana (Cda)

Delaying a script to nearest quarter hour?

Recommended Posts

Diana (Cda)

I'd like to finetune a script I have in terms of when it loops launching an application. If I started it up now, at 06:39:50 a.m. (as I type), how could we get AI to wait for it to do its thing until gets to 06:45:00, the nearest quarter hour?

I imagine that after that, if we've set the script to loop every 15 minutes, it would then run the app every quarter hour on the quarter hour?

Thanks! :oD

Edited by Diana (Cda)

Share this post


Link to post
Share on other sites
Melba23

Diana (Cda),

Try something like this (I have used @SEC rather than @MIN to speed up the demo, but the principle is the same):

HotKeySet("{ESC}", "On_Exit")

$Last_Sec = ""

While 1

    While 1

        Switch @SEC
            Case 00, 15, 30, 45
                $Sec = @SEC
                ExitLoop
        EndSwitch
        Sleep(10)

    WEnd

    If $Last_Sec <> $Sec Then
        ConsoleWrite($Sec & @CRLF)
        $Last_Sec = $Sec
    EndIf

WEnd

Func On_Exit()
    Exit
EndFunc

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites
Diana (Cda)

Hi! Something new again; I can't seem to "read" this code so I can't figure out 100% what it's doing <wry grin>. I left my launch code where it was and put this at the top. App wasn't launched. Okay. Then I did the old, "let's put my code in to these logical spots it might go", but that approach didn't work this time <g>. Script still sits in the systray, so of course, I'm doing something wrong ... again! <g>.

p.s., will this _just_ delay the script x number of minutes (or seconds with this code here <lol>)? The "Case 00, 15, 30, 45" makes me wonder. The rest of my script actually already determines the loop interval, in case that is what this 00, 15, 30, 45 reference is. I just didn't know how to approach a delay to nearest quarter hour (or actually whatever other time delay needed).

:)

Share this post


Link to post
Share on other sites
Melba23

Diana (Cda),

OK, let us go through the relevant sections of the code slowly - most of it was just there to show you how it worked (and I used seconds rather than minutes because it was faster! :) ).

You start your script at a random time (say 06:39:50) and you want it to wait until the next quarter hour point. At the quarter hour point, the minutes read 00, 15, 30 or 45 - we must wait until this is the case, i.e. 06:45:00.

So we set up a loop waiting until the @MIN macro returns one of the magic figures 00, 15, 30, 45:

While 1
    Switch @MIN
            Case 00, 15, 30, 45 ; Is it a quarter hour?
                ExitLoop ; Yes it is a quarter hour point so exit the loop and start running your script
    EndSwitch
    ; if we get here it is not  quarter hour and so we continue the loop
    Sleep(10) ; to prevent CPU overheating in a tight loop
WEnd

; Your script goes here

You say that you have already coded the timing interval so this code has done its job. :)

I hope this is clearer. Please ask again if not.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.