AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Start and Stop time

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
BillyJ
Guest





PostPosted: Wed Dec 31, 2008 11:16 pm    Post subject: Start and Stop time Reply with quote

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

PostPosted: Thu Jan 01, 2009 6:02 pm    Post subject: Round about method Reply with quote

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
View user's profile Send private message
SpiderGames



Joined: 09 Jun 2008
Posts: 936
Location: Canada

PostPosted: Thu Jan 01, 2009 9:52 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Slanter



Joined: 28 May 2008
Posts: 739
Location: Minnesota, USA

PostPosted: Thu Jan 01, 2009 9:54 pm    Post subject: Reply with quote

Instead of FormatTime on a timer, you can simply use the built in variable A_Hour. Also, that if statement needs help Wink
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
View user's profile Send private message Visit poster's website
SpiderGames



Joined: 09 Jun 2008
Posts: 936
Location: Canada

PostPosted: Thu Jan 01, 2009 10:10 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
BillyJ
Guest





PostPosted: Fri Jan 02, 2009 12:20 am    Post subject: Reply with 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
Back to top
SpiderGames



Joined: 09 Jun 2008
Posts: 936
Location: Canada

PostPosted: Fri Jan 02, 2009 12:54 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
BillyJ
Guest





PostPosted: Fri Jan 02, 2009 1:06 am    Post subject: Reply with quote

Oops, thanks Embarassed
Back to top
Neight



Joined: 31 Dec 2008
Posts: 23

PostPosted: Fri Jan 02, 2009 3:48 am    Post subject: Reply with quote

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
View user's profile Send private message
Frankie



Joined: 02 Nov 2008
Posts: 2850

PostPosted: Fri Jan 02, 2009 5:50 am    Post subject: Reply with quote

Your a bit over critical. Last time I checked that timer is infinate too.
_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run
Back to top
View user's profile Send private message
Neight



Joined: 31 Dec 2008
Posts: 23

PostPosted: Fri Jan 02, 2009 5:53 am    Post subject: Reply with quote

With a delay =\
_________________
Ask stupid questions, get stupid answers.
Search before posting!
Back to top
View user's profile Send private message
Frankie



Joined: 02 Nov 2008
Posts: 2850

PostPosted: Fri Jan 02, 2009 5:53 am    Post subject: Reply with quote

True...
_________________
aboutscriptappsscripts
Any code ⇈ above ⇈ requires AutoHotkey_L to run
Back to top
View user's profile Send private message
SpiderGames



Joined: 09 Jun 2008
Posts: 936
Location: Canada

PostPosted: Fri Jan 02, 2009 4:33 pm    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group