Jump to content

Pls help, simple script to run on certain times...


 Share

Recommended Posts

Hello and thank you for your time, I've been killing myself trying to read so many pages but for the life of me, can not do this, All I need is help creating a script in autoit which will, upon click, check if it's between certain times on weekdays and run something, and if it's on Saturday then run it half time, something like this:

$StartTime1 = "10:00"
$EndTime1   = "11:00"
$StartTime2 = "16:00"
$EndTime2   = "18:00"

  if @WDAY = 1,2,3,4,5,6 AND @HOUR & ":" & @MIN = BETWEEN $StartTime1 AND $EndTime1 OR $StartTime2 AND $EndTime2  Then

        RUN (some program)

  EndIf

  if @WDAY = 7 AND @HOUR & ":" & @MIN = BETWEEN $StartTime2 AND $EndTime2  Then

        RUN (some program)

  EndIf

Really, forgive me as I honestly tried hard on this.

Mohd.

Link to comment
Share on other sites

fatboy123, see if this helps:

$StartTime1 = "10";:00"
$EndTime1   = "11";:00"
$StartTime2 = "16";:00"
$EndTime2   = "18";:00"
Switch @WDAY
Case 1 To 6
If BitOR($StartTime1 <= @HOUR And @HOUR<= $EndTime1, $StartTime2<= @HOUR And @HOUR<= $EndTime2) Then ConsoleWrite("1-6"&@CRLF);Run($sProgram1)
Case 7
If BitOR($StartTime1 <= @HOUR And @HOUR<= $EndTime1, $StartTime2<= @HOUR And @HOUR<= $EndTime2) Then ConsoleWrite("7"&@CRLF);Run($sProgram2)
EndSwitch

I assumed that the minutes are 0.

Link to comment
Share on other sites

Just encase that code doesn't work "and i am sure it does but i am still mostly new myself :D" but if your using windows 7 you could use task Task Scheduler to run your scripts between allotted times. Though i agree its best to try and keep everything self contained within our complied .exes just a thought if u run out of other ideas :oops:

Link to comment
Share on other sites

Taietel,

THANK YOU SO MUCH, believe me you saved me at least 5 days of reading, GOD bless you. I just played around with your code in order to customize it more to my liking, can you check if everything is alright with this? it does run great...

#include <Date.au3>  ;  1 = Sun  2 = Mon  3 = Tue  4 = Wed  5 = Thu  6 = Fri  7 = Sat
$StartTime1 = "07:30"
$EndTime1   = "08:30"
$StartTime2 = "16:30"
$EndTime2   = "18:30"
$CurrentTime = _NowTime(4)

Switch @WDAY
Case 1,2,3,4,5,7
If BitOR($CurrentTime >= $StartTime1 AND $CurrentTime <= $EndTime1, $CurrentTime >= $StartTime2 AND $CurrentTime <= $EndTime2) Then
MSGBOX(0,"Test1","Test1")
EndIf

Case 6
If ($CurrentTime >= $StartTime2 AND $CurrentTime <= $EndTime2) Then
MSGBOX(0,"Test2","Test2")
EndIf
EndSwitch

IanN1990, thanks for the idea, I actually DO have my original script scheduled in windows 7 as you have mentioned, the trouble is I'm having a horrible case of BSOD on my machine and it keeps restarting every hour or two, so I thought I sort that out I'll just put this script in the windows start-up folder.

Thanks again.

Mohd.

Link to comment
Share on other sites

fatboy123, my pleasure. :D

If you put the script in the startup folder, here is a slightly modified version:

#include <Date.au3>  ;  1 = Sun  2 = Mon  3 = Tue  4 = Wed  5 = Thu  6 = Fri  7 = Sat
$StartTime1 = "07:30"
$EndTime1 = "08:30"
$StartTime2 = "16:30"
$EndTime2 = "18:30"
AdlibRegister("_Check",1000*60);check every minute

While 1;just idle around
Sleep(1000)
WEnd

Func _Check();every minute we check
$CurrentTime = _NowTime(4);the current time
Switch @WDAY;check for D-day and start the program (a message in this case)
Case 1, 2, 3, 4, 5, 7
If BitOR($CurrentTime >= $StartTime1 And $CurrentTime <= $EndTime1, $CurrentTime >= $StartTime2 And $CurrentTime <= $EndTime2) Then MsgBox(0, "Test1", "Test1")
Case 6
If ($CurrentTime >= $StartTime2 And $CurrentTime <= $EndTime2) Then MsgBox(0, "Test2", "Test2")
EndSwitch
AdlibUnRegister();unregister the running function
Exit;and exit
EndFunc

Best regards,

taietel

Link to comment
Share on other sites

Well if you want it to run once, then exit after checking, remove these lines:

AdlibRegister("_Check",1000*60);check every minute

While 1;just idle around
Sleep(1000)
WEnd

Func _Check();every minute we check

AdlibUnRegister();unregister the running function
Exit;and exit
EndFunc
Edited by somdcomputerguy

- Bruce /*somdcomputerguy */  If you change the way you look at things, the things you look at change.

Link to comment
Share on other sites

You should be good, unless your start/stop time periods ever span midnight?

Starting at 20:00 and ending at 02:00 raises issues...

I'd done the bit below a long time ago. It kicks off a process at a set time and kills it at a set time.

The script was intended to run continuously, day after day.

It's not quite what you're doing, but shows the need to include the date in your variables and an example of some coding to handle work cycles that span midnight.

#include <Date.au3>
Global $sState = False, $aTime[3] = ["15:40:00", "02:42:00", ""] ; start/end/trigger

$aTime[2] = _NowCalcDate() & " " & $aTime[0] ; set initial trigger time to start time
If ($aTime[1] > $aTime[0]) Then ; run does not span midnight
    If _NowCalc() > _NowCalcDate() & " " & $aTime[1] Then $aTime[2] = _DateAdd("D", 1, $aTime[2]) ; set start to next day
Else ; run spans midnight
    If _NowCalc() < _NowCalcDate() & " " & $aTime[1] Then $aTime[2] = _DateAdd("D", -1, $aTime[2]) ; set start to prior day
EndIf

;===================================================================================================================================
While 1
    If _NowCalc() >= $aTime[2] Then Toggle_Switch()
    Tooltip("Switch state: " & $sState & "  Now: " & _NowCalc() & " Next change: " & $aTime[2]) ; for testing
    Sleep(5000)
WEnd
;===================================================================================================================================
Func Toggle_Switch()
    Beep(800,100); just for fun
    $sState = (Not $sState) ; toggle switch
    $aTime[2] = _NowCalcDate() & " " & $aTime[$sState] ; set next trigger time
    If $sState Then ; switch was turned on
;      Start_Process()
        If $aTime[0] > $aTime[1] Then $aTime[2] = _DateAdd("D", 1, $aTime[2]) ; if run spans midnight, set end to next day
    Else ; switch was turned off
;      End_Process()
        If $aTime[1] > $aTime[0] Then $aTime[2] = _DateAdd("D", 1, $aTime[2]) ; if doesn't span midnight, set start to next day
    EndIf
EndFunc
Edited by Spiff59
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...