 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
tcgbp
Joined: 04 Apr 2008 Posts: 24 Location: China
|
Posted: Sun May 25, 2008 12:49 pm Post subject: How to run commands at a certain time without using loop? |
|
|
I want the computer to be closed at 2 am everyday and until 6 or 7 am no one could open it again cause they use my computer at night and I can not fall in sleep easily. So please help me!
[ Moderator!: [b/b] tag removed ] |
|
| Back to top |
|
 |
Krogdor
Joined: 18 Apr 2008 Posts: 1390 Location: The Interwebs
|
Posted: Sun May 25, 2008 5:37 pm Post subject: |
|
|
Unfortunately, under the features pending implementation:
| The Manual wrote: | | Add scheduling by extending SetTimer, e.g. daily at a certain time, etc. |
Meaning that currently we do not have that feature. I have a couple of features that I simply use SetTimer checking the time to decide whether or not they activate, which as far as I know is the only current way. |
|
| Back to top |
|
 |
Z Gecko Guest
|
|
| Back to top |
|
 |
Guest
|
Posted: Mon May 26, 2008 5:20 am Post subject: |
|
|
Something like this should work, as long as you start it before midnight on the day you want it to do something.
| Code: | Time = 2:00 ; time - HH24:MM
T := 86400 - (SubStr(A_Now,-5,2)*60 + SubStr(A_Now,-3,2))*60 + SubStr(A_Now,-1,2) + (RegExReplace(Time,"^[0-9]{1,2}:([0-9]{2})$","$1") + RegExReplace(Time,"^([0-9]{1,2}):[0-9]{2}$","$1")*60)*60
SetTimer, DoSomething, % T*1000 ; DoSomething at "Time" |
|
|
| Back to top |
|
 |
tcgbp
Joined: 04 Apr 2008 Posts: 24 Location: China
|
Posted: Mon May 26, 2008 5:58 pm Post subject: |
|
|
| Krogdor wrote: | Unfortunately, under the features pending implementation:
| The Manual wrote: | | Add scheduling by extending SetTimer, e.g. daily at a certain time, etc. |
Meaning that currently we do not have that feature. I have a couple of features that I simply use SetTimer checking the time to decide whether or not they activate, which as far as I know is the only current way. | Could it can pass the first time to run? |
|
| Back to top |
|
 |
tcgbp
Joined: 04 Apr 2008 Posts: 24 Location: China
|
Posted: Mon May 26, 2008 6:02 pm Post subject: |
|
|
| Anonymous wrote: | Something like this should work, as long as you start it before midnight on the day you want it to do something.
| Code: | Time = 2:00 ; time - HH24:MM
T := 86400 - (SubStr(A_Now,-5,2)*60 + SubStr(A_Now,-3,2))*60 + SubStr(A_Now,-1,2) + (RegExReplace(Time,"^[0-9]{1,2}:([0-9]{2})$","$1") + RegExReplace(Time,"^([0-9]{1,2}):[0-9]{2}$","$1")*60)*60
SetTimer, DoSomething, % T*1000 ; DoSomething at "Time" |
| Who are you body? That's exactly what I want and qqq so much! |
|
| Back to top |
|
 |
tcgbp
Joined: 04 Apr 2008 Posts: 24 Location: China
|
Posted: Mon May 26, 2008 6:10 pm Post subject: |
|
|
| Code: | StringMid,MC,A_Now,11,2
StringMid,HC,A_Now,9,2
DL := (60-MC+(25-HC)*60)*60000
If (A_Hour > 1 And A_Hour < 7)
{
Shutdown 5
}
Sleep %DL%
Shutdown 5 | Now I use such code and it works well. |
|
| Back to top |
|
 |
VOODOOS!L Guest
|
Posted: Tue Sep 20, 2011 3:13 pm Post subject: |
|
|
based on some code I found in this thread, I created my own timer: if you specify a time in the future, it will count down to that time and launch. If you specify a time already passed for today, it will add 24hours so it can run at the specified time tomorrow.
| Code: |
; Time Registration
#Persistent
#SingleInstance,force
REGISTER_FUTURE:
TNowHour := SubStr(A_Now,-5,2)
TNowMin := SubStr(A_Now,-3,2)
TNowSec := SubStr(A_Now,-1,2)
TNowInSec := ((TNowHour*60 + TNowMin) * 60 + TNowSec)
TParamHour := RegExReplace(timeParam,"^([0-9]{1,2}):[0-9]{2}$","$1")
TParamMin := RegExReplace(timeParam,"^[0-9]{1,2}:([0-9]{2})$","$1")
TParamInSec := (TParamHour*60 + TParamMin) * 60
delayInSec := 0
If (TParamInSec > TNowInSec) {
;now : 9u00
;to run: 9u05
;delay = 5min = 9u05 - 9u00
delayInSec := TParamInSec - TNowInSec
} else {
; now : 9u05
; to run: 9u00
; delay = 24u - 5min = 86400 sec - (9u05 - 9u00)
delayInSec := 86400 - ( TNowInSec - TParamInSec)
}
SetTimer, REGISTER_NOW, % delayInSec*-1000 ; convert to millisec and make negative to denote only run once
TrayTip, Timer configured, Start in %delayInSec%sec at %TParamHour%:%TParamMin%
;MsgBox Timer configured in: %delayInSec% sec at %TParamHour%:%TParamMin%
return
DISABLE_FUTURE:
SetTimer, REGISTER_NOW, Off
return
REGISTER_NOW:
;add code to be executed at exact time you provided
return |
|
|
| Back to top |
|
 |
VOODOOS!L Guest
|
Posted: Tue Sep 20, 2011 3:16 pm Post subject: |
|
|
in my previous post, I should have added:
timeParam should contain the exact time at witch the timer should be exectued, in format HH:MM |
|
| Back to top |
|
 |
Guest
|
Posted: Mon Oct 03, 2011 2:30 pm Post subject: |
|
|
I'm trying to run this modified timer, but setting timeParam doesn't seem to work right. The way I interpret your instructions, I should put a time like 19:45, or like 1945, or maybe like 19.45. I tried the former and got the error that a ":" is missing its "?". It accepted times of the form '0600', or '0'.
But then with a time that is supposed to be 1 minute in the future, it says the alarm will go off in "218846 seconds" at "0604:0604". Same issue with "06.33:06.33". |
|
| Back to top |
|
 |
Guest
|
Posted: Wed Oct 05, 2011 3:35 am Post subject: |
|
|
| Code: | error := 19:45 ; Invalid - two numbers separated by : operator.
okay := "19:45" ; Quoted string in an expression.
okay = 19:45 ; Literal (non-expression) assignment.
|
|
|
| Back to top |
|
 |
Guest
|
Posted: Wed Oct 05, 2011 9:16 am Post subject: |
|
|
| Thanks for the explanation! |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|