Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

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


  • Please log in to reply
11 replies to this topic
tcgbp
  • Members
  • 24 posts
  • Last active: Sep 19 2009 12:32 PM
  • Joined: 04 Apr 2008
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 ]

Krogdor
  • Members
  • 1391 posts
  • Last active: Jun 08 2011 05:31 AM
  • Joined: 18 Apr 2008
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.

Z Gecko
  • Guests
  • Last active:
  • Joined: --
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

  • Guests
  • Last active:
  • Joined: --
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"


tcgbp
  • Members
  • 24 posts
  • Last active: Sep 19 2009 12:32 PM
  • Joined: 04 Apr 2008

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?

tcgbp
  • Members
  • 24 posts
  • Last active: Sep 19 2009 12:32 PM
  • Joined: 04 Apr 2008

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!

tcgbp
  • Members
  • 24 posts
  • Last active: Sep 19 2009 12:32 PM
  • Joined: 04 Apr 2008
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.

VOODOOS!L
  • Guests
  • Last active:
  • Joined: --
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


VOODOOS!L
  • Guests
  • Last active:
  • Joined: --
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

  • Guests
  • Last active:
  • Joined: --
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".

  • Guests
  • Last active:
  • Joined: --
error :=  19:45  ; Invalid - two numbers separated by : operator.

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

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



  • Guests
  • Last active:
  • Joined: --
Thanks for the explanation!