| View previous topic :: View next topic |
| Author |
Message |
BillyJ Guest
|
Posted: Wed Dec 31, 2008 11:16 pm Post subject: Start and Stop time |
|
|
| Would anyone happen to know how to say have a script running at all times, but only be functional between 7AM and 7PM? |
|
| Back to top |
|
 |
Thrillski
Joined: 18 Jul 2007 Posts: 143 Location: South Florida
|
Posted: Thu Jan 01, 2009 6:02 pm Post subject: Round about method |
|
|
Good morning!
How about this:
You have your program running all the time...
[1] Create a script that will terminate the program. Run this from Windows Scheduler at 7PM.
[2] Use the Windows scheduler to start your program at 7AM.
[3] Write a time-check routine to be done at bootup to determine if the program should be run or not. (Otherwise when you boot, your program won't run again until 7AM, even if booted at 7:01 AM)
Don't make things more complicated than they need to be and don't re-invent the wheel. |
|
| Back to top |
|
 |
SpiderGames
Joined: 09 Jun 2008 Posts: 936 Location: Canada
|
Posted: Thu Jan 01, 2009 9:52 pm Post subject: |
|
|
| Code: |
FormatTime, date, HH24 ; get the time in hours
SetTimer, reload, 20000 ; set a timer to go off every 20 seconds
^t:: ; on T
if date = > 7 & < 19 ; if between 7am adn 7pm
{
;your script here
}
Return
reload: ; timer Lable
FormatTime, date, HH24 ; resets the time
return, |
_________________
I know i have 6 legs. It's cuz I'm special. |
|
| Back to top |
|
 |
Slanter
Joined: 28 May 2008 Posts: 739 Location: Minnesota, USA
|
Posted: Thu Jan 01, 2009 9:54 pm Post subject: |
|
|
Instead of FormatTime on a timer, you can simply use the built in variable A_Hour. Also, that if statement needs help | Code: | ^t:: ; ctrl + T
if A_Hour between 7 and 19 ; if between 7am and 7pm
{
;your script here
}
Return |
_________________ Unless otherwise stated, all code is untested
(\__/) This is Bunny.
(='.'=) Cut, copy, and paste bunny onto your sig.
(")_(") Help Bunny gain World Domination. |
|
| Back to top |
|
 |
SpiderGames
Joined: 09 Jun 2008 Posts: 936 Location: Canada
|
Posted: Thu Jan 01, 2009 10:10 pm Post subject: |
|
|
ah yes i forgot about that one. Saves some work _________________
I know i have 6 legs. It's cuz I'm special. |
|
| Back to top |
|
 |
BillyJ Guest
|
Posted: Fri Jan 02, 2009 12:20 am Post subject: |
|
|
I'm not too sure if that's working, my code is as follows (it's on a loop):
if A_Hour between 7 and 19 ; if between 7am and 7pm
{
Loop {
*Code*
}
}
Return |
|
| Back to top |
|
 |
SpiderGames
Joined: 09 Jun 2008 Posts: 936 Location: Canada
|
Posted: Fri Jan 02, 2009 12:54 am Post subject: |
|
|
| Quote: | I'm not too sure if that's working, my code is as follows (it's on a loop):
if A_Hour between 7 and 19 ; if between 7am and 7pm
{
Loop {
*Code*
}
}
Return |
Of course not.
| Code: |
if A_Hour between 7 and 19 ; if between 7am and 7pm
{
Loop {
*Code*
}
}
|
it's only checking the time once. Put the IF comand in the loop.
| Code: |
Loop {
if A_Hour between 7 and 19 ; if between 7am and 7pm
{
*Code*
}
} |
_________________
I know i have 6 legs. It's cuz I'm special. |
|
| Back to top |
|
 |
BillyJ Guest
|
Posted: Fri Jan 02, 2009 1:06 am Post subject: |
|
|
Oops, thanks  |
|
| Back to top |
|
 |
Neight
Joined: 31 Dec 2008 Posts: 23
|
Posted: Fri Jan 02, 2009 3:48 am Post subject: |
|
|
| SpiderGames wrote: | | Code: |
Loop {
if A_Hour between 7 and 19 ; if between 7am and 7pm
{
*Code*
}
} |
|
What a horrible way of coding; Never use infinite loops..
| Code: | SetTimer, Time, 15000 ; Check every 15 seconds
Time:
If A_Hour Between 7 And 19
{
; Your code here
} |
_________________ Ask stupid questions, get stupid answers.
Search before posting! |
|
| Back to top |
|
 |
Frankie
Joined: 02 Nov 2008 Posts: 2850
|
Posted: Fri Jan 02, 2009 5:50 am Post subject: |
|
|
Your a bit over critical. Last time I checked that timer is infinate too. _________________ aboutscript ⍟ apps ⍟ scripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run |
|
| Back to top |
|
 |
Neight
Joined: 31 Dec 2008 Posts: 23
|
Posted: Fri Jan 02, 2009 5:53 am Post subject: |
|
|
With a delay =\ _________________ Ask stupid questions, get stupid answers.
Search before posting! |
|
| Back to top |
|
 |
Frankie
Joined: 02 Nov 2008 Posts: 2850
|
Posted: Fri Jan 02, 2009 5:53 am Post subject: |
|
|
True... _________________ aboutscript ⍟ apps ⍟ scripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run |
|
| Back to top |
|
 |
SpiderGames
Joined: 09 Jun 2008 Posts: 936 Location: Canada
|
Posted: Fri Jan 02, 2009 4:33 pm Post subject: |
|
|
personaly I would have it check the time in a loop outside this loop then if that time is correct start loop with an IF comand and a sleep.
But to keep it simple i just took his code, and made it work. _________________
I know i have 6 legs. It's cuz I'm special. |
|
| Back to top |
|
 |
|