| View previous topic :: View next topic |
| Author |
Message |
grbaseball
Joined: 15 Dec 2008 Posts: 2 Location: Florida
|
Posted: Mon Dec 15, 2008 4:29 am Post subject: auto launch a program at a certain time |
|
|
I am trying to create script to automatically launch a program at 9:00 am but only on Monday - Friday without the need of pressing any hotkeys. Basically I'd like my work pc to auto launch my main work program before I come into work so its already loaded and ready to go. I am relatively new to autohotkey but have gotten the basics down. I have looked through these forums and done searches but could really only find script that did timed actions (such as launch a process every hour) which doesn't work in my case. I would think there should be some type of command that could do something like this
#persistent
SetTimer, WorkProgram, 1000, 0
WorkProgram:
If {
system time = 09:00:00
A_day = Monday or Tuesday or Wedneday or Thursday or Friday
}
run program.exe
return
Any help or suggestions on script would be greatly appreciated as this is driving me nuts! |
|
| Back to top |
|
 |
Slanter
Joined: 28 May 2008 Posts: 739 Location: Minnesota, USA
|
Posted: Mon Dec 15, 2008 4:47 am Post subject: |
|
|
This should work
| Code: | #persistent
SetTimer, WorkProgram, 1000
WorkProgram:
If (A_Hour = 9 && A_WDay > 1 && A_WDay < 7) {
SetTimer, WorkProgram, off
RunWait program.exe
SetTimer, WorkProgram, 1000
}
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 |
|
 |
Guest
|
|
| Back to top |
|
 |
mikek
Joined: 21 Nov 2008 Posts: 54 Location: Monterey, California
|
Posted: Mon Dec 15, 2008 5:08 pm Post subject: |
|
|
Is there a benefit to using this technique over using the Scheduled Tasks control panel? I ask because I've been using the Scheduled Tasks control panel, and am wondering if the method posted has any advantages.
- Mike |
|
| Back to top |
|
 |
jaco0646
Joined: 07 Oct 2006 Posts: 3113 Location: MN, USA
|
Posted: Mon Dec 15, 2008 11:24 pm Post subject: |
|
|
| mikek wrote: | | Is there a benefit to using this technique over using the Scheduled Tasks control panel? |
No. Running a script every second of every day to check the time is ridiculous. That's 604,800 iterations to launch a program 5 times.  |
|
| Back to top |
|
 |
evan Guest
|
Posted: Tue Dec 16, 2008 1:39 am Post subject: |
|
|
method without using settimer:
| Code: | hour = 09
min = 00
difhr := hour - A_hour
difmin := min - A_min
if difhr > 0
sleepH := difhr * 3600000
else
sleepH := (24 + difhr) * 3600000
if difmin > 0
sleepM := difmin * 60000
else
sleepM := (60 + difmin) * 60000
totalsleep := sleepH + sleepM
msgbox, %totalsleep%ms to %hour%:%min%
sleep %totalsleep%
Run, this program
reload
return |
|
|
| Back to top |
|
 |
grbaseball
Joined: 15 Dec 2008 Posts: 2 Location: Florida
|
Posted: Tue Dec 16, 2008 4:49 pm Post subject: |
|
|
I was able to use the code suggested by slanter, however I had to tweak it as it does a check every second to see if the hour is 9 which causes program.exe to get launched every second during the 9am hour. here was what i ended up with:
| Code: | loop {
if A_WDay between 2 and 6
{
if (A_Hour = 08) and (A_Min = 55) ; is time 8:55am?
GoSub, AutoLogon
}
sleep, 1000 * 60 ; sleep for 60 seconds so only loop once per minute
}
return
AutoLogon:
Run C:\Program Files\Program.exe ;replaced actual program name with program.exe for display purposes
return |
This works assuming the pc is active and logged in. I have a separate 'stay alive' macro running to keep the PC from auto locking out at the end of the night |
|
| Back to top |
|
 |
|