Sign in to follow this  
Followers 0
Scottswan

Run at a certain time every day.

13 posts in this topic

I see that there are a number of ways to do this but I'm wondering if someone has already implemented a way so that Autoit isn't checking the clock all the time.

What I want to do is run a backup utility at 2am every day. The run part is no problem, but I'm not sure of the best way to get the timing stuff done.

I could use this:

#include <Date.au3>
MsgBox(0,'',"The time is:" & _NowTime())

And set a 24 hour sleep time before it checks the _NowTime again.

Then do a little math... target_time - now_time = time_until_run_application, then set a sleep time or _TimeToTicks based on that value for the delay before the run.

That way I won't be checking the time very often but I will still be in sync with the PC clock if the Autoit program stops for some reason.

Better ideas?

-Scott

Share this post


Link to post
Share on other sites



I see that there are a number of ways to do this but I'm wondering if someone has already implemented a way so that Autoit isn't checking the clock all the time.

What I want to do is run a backup utility at 2am every day. The run part is no problem, but I'm not sure of the best way to get the timing stuff done.

I could use this:

#include <Date.au3>
MsgBox(0,'',"The time is:" & _NowTime())

And set a 24 hour sleep time before it checks the _NowTime again.

Then do a little math... target_time - now_time = time_until_run_application, then set a sleep time or _TimeToTicks based on that value for the delay before the run.

That way I won't be checking the time very often but I will still be in sync with the PC clock if the Autoit program stops for some reason.

Better ideas?

-Scott

that would work, but i think a 24 hour sleep is way more than you need. even if you have it wait an hour between checks, you're not even going to notice an impact to your processor usage. it may be easier to avoid the sleep completely though, and just use a task scheduler to run your program at the appropriate time...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

I see that there are a number of ways to do this but I'm wondering if someone has already implemented a way so that Autoit isn't checking the clock all the time.

What I want to do is run a backup utility at 2am every day. The run part is no problem, but I'm not sure of the best way to get the timing stuff done.

I could use this:

#include <Date.au3>
MsgBox(0,'',"The time is:" & _NowTime())

And set a 24 hour sleep time before it checks the _NowTime again.

Then do a little math... target_time - now_time = time_until_run_application, then set a sleep time or _TimeToTicks based on that value for the delay before the run.

That way I won't be checking the time very often but I will still be in sync with the PC clock if the Autoit program stops for some reason.

Better ideas?

-Scott

Computers can calculate lots of thing in one milisecond so simpli check the @hour like every minute it won't cost much cpu then.

This could work savely also display message box only once not every milisecond of a hour

$donetoday = 0
$day = @yday
While 1
    sleep(60000); check every 60 seconds
    if $donetoday = 0 and @hour = 2 then 
        msgbox(64,"Hello","Its 2 am again time to go sleep you need to wake up at 6",360); wait hour to remove the box automaticly
        $donetoday = 1
        $day = @yday
    endif
    if ($donetoday = 1) and NOT ($day = @yday) then 
        $donetoday = 0
        $day = @yday
    endif
Wend

Share this post


Link to post
Share on other sites

There was a similar post made this morning on 'Time' topic. I had not seen the _TicksToTime() UDF before, but it may be what your looking for.

Spacely gave a good example, but I'm not a specific fan of 'Sleep()' for time functions.

Take a look at this Topic and post and see if it gives you any ideas: http://www.autoitscript.com/forum/index.ph...ndpost&p=133816

Also, if you do a search for 'Alarm Clock', I'm sure the Sripts and Scraps will have a few 'daily' time functions to take a look at. I know that Valauter had done some Time Function work too for a Work enviroment UDF, like clocking in and out.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Here is an alarm clock I picked up on the forums a while back

#include <GuiConstants.au3>
Global $sec = @SEC, $minute, $hour, $light, $time, $clocklabel
opt("WinWaitDelay", 100)
opt("WinTitleMatchMode", 4)
opt("WinDetectHiddenText", 1)
opt("MouseCoordMode", 0)
GUICreate("Max's Clock", 200, 50, (@DesktopWidth - 188) / 2, (@DesktopHeight - 59) / 2)
$clocklabel = GUICtrlCreateLabel("Loading...", 5, 5, 190, 40, 0x1000)
GUICtrlSetFont($clocklabel, 24)
GUISetState()
While 1
    $msg = GUIGetMsg()
    If $msg = -3 Then
        ExitLoop
    ElseIf $sec <> @SEC Then
        GUICtrlSetData($clocklabel, TimeSet())
        AlarmCheck(TimeSet())
    EndIf
WEnd
Exit
Func AlarmCheck($time)
If $time = "9:00:00 PM"Then
MsgBox(0,"","Time to call it a night");Alarm function(configure how wanted)
EndIf
EndFunc ;==>AlarmCheck
Func TimeSet()
    $light = " AM"
    $hour = @HOUR
    $minute = @MIN
    $sec = @SEC
    If $hour = 0 Then
        $hour = 12
    ElseIf $hour = 12 Then
        $light = " PM"
    ElseIf $hour > 12 Then
        $hour = (@HOUR) - 12
        $light = " PM"
    EndIf
    $time = $hour & ":" & $minute & ":" & $sec & $light
    Return $time
EndFunc ;==>TimeSet

This was not written by me.



Get Beta versions Here Get latest SciTE editor Here AutoIt 1-2-3 by Valuater - A great starting point.

Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Share this post


Link to post
Share on other sites

Or to "think outside the box" as it were... you could always just schedule the job to run daily with windows built-in Scheduled Tasks.


[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Or to "think outside the box" as it were... you could always just schedule the job to run daily with windows built-in Scheduled Tasks.

Actually... wouldn't that be considered 'inside the box' :P


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Actually... wouldn't that be considered 'inside the box' :P

that's what i was thinking when i suggested it in the first reply...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

@ Smoke :P

@ Cam dangit... missed that

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Or to "think outside the box" as it were... you could always just schedule the job to run daily with windows built-in Scheduled Tasks.

I thought about that at first, then I discovered that the backup utility (xxclone) won't let me use a command line 'run' unless I cough up $40 for the pro version. So I need something that can actually hit {Enter}.

Plus there are a couple other 'batch' style jobs I need to run daily and some hourly on this machine so I figured I'd just make it all work with Autoit.

The machine is going to be an un-manned server running a portal for a small company.

Thanks for the tips so far, I need to look into the other tips yet.

-Scott

Share this post


Link to post
Share on other sites

I thought about that at first, then I discovered that the backup utility (xxclone) won't let me use a command line 'run' unless I cough up $40 for the pro version. So I need something that can actually hit {Enter}.

Plus there are a couple other 'batch' style jobs I need to run daily and some hourly on this machine so I figured I'd just make it all work with Autoit.

The machine is going to be an un-manned server running a portal for a small company.

Thanks for the tips so far, I need to look into the other tips yet.

-Scott

while we're talking about autoit based solutions... why do you need a command line? why can't you just controlsend the "{ENTER}" or controlclick on the "i agree to the terms imposed by my using the cheap version" box? and still use regular scheduler...

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

while we're talking about autoit based solutions... why do you need a command line? why can't you just controlsend the "{ENTER}" or controlclick on the "i agree to the terms imposed by my using the cheap version" box? and still use regular scheduler...

There's a thought. Just have ms scheduler run an Autoit script that runs xxclone and then hits {enter}, which is defaulted to the 'start' button on the xxclones gui, then end the script... done!

Duh! :P

Edited by Scottswan

Share this post


Link to post
Share on other sites

There's a thought. Just have ms scheduler run an Autoit script that runs xxclone and then hits {enter}, which is defaulted to the 'start' button on the xxclones gui, then end the script... done!

Duh! :P

sometimes it just takes hearing it from someone else. glad i could help.

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

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  
Followers 0