Jump to content


Photo

How to run commands at a certain time without using loop?


  • Please log in to reply
11 replies to this topic

#1 tcgbp

tcgbp
  • Members
  • 24 posts

Posted 25 May 2008 - 12:49 PM

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 ]

#2 Krogdor

Krogdor
  • Members
  • 1391 posts

Posted 25 May 2008 - 05:37 PM

Unfortunately, under the features pending implementation:

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.

#3 Z Gecko

Z Gecko
  • Guests

Posted 25 May 2008 - 06:25 PM

If you don“t want to use SetTimer,
you could try out the task-scheduler of windows.

More Info:
http://www.autohotke...t=schedule task
http://www.autohotke...t=schedule task

#4 Guests

  • Guests

Posted 26 May 2008 - 05:20 AM

Something like this should work, as long as you start it before midnight on the day you want it to do something.
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"


#5 tcgbp

tcgbp
  • Members
  • 24 posts

Posted 26 May 2008 - 05:58 PM

Unfortunately, under the features pending implementation:

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?

#6 tcgbp

tcgbp
  • Members
  • 24 posts

Posted 26 May 2008 - 06:02 PM

Something like this should work, as long as you start it before midnight on the day you want it to do something.

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!

#7 tcgbp

tcgbp
  • Members
  • 24 posts

Posted 26 May 2008 - 06:10 PM

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.

#8 VOODOOS!L

VOODOOS!L
  • Guests

Posted 20 September 2011 - 03:13 PM

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.

; 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


#9 VOODOOS!L

VOODOOS!L
  • Guests

Posted 20 September 2011 - 03:16 PM

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

#10 Guests

  • Guests

Posted 03 October 2011 - 02:30 PM

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".

#11 Guests

  • Guests

Posted 05 October 2011 - 03:35 AM

error :=  19:45  ; Invalid - two numbers separated by : operator.

okay  := "19:45" ; Quoted string in an expression.

okay   =  19:45  ; Literal (non-expression) assignment.



#12 Guests

  • Guests

Posted 05 October 2011 - 09:16 AM

Thanks for the explanation!