run automatically during certain hours

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
SchmutzigeT
Posts: 3
Joined: 05 May 2021, 07:12

run automatically during certain hours

05 May 2021, 07:24

Hi Ladies and Gents,

I've got a program I like to run automatically during certain hours (for example between 08:00 and 19:00) and close the program after that time.
And also start it again when it's 08:00. And if the program shuts down between 08:00 for whatever reason it will start it again after for example after 60 sec.
It's for a gallery space so they can just keep the computer on and it runs automatically.

I think I got a base for starting and keeping watch for the program but some help for the rest would be nice ;) :

Code: Select all

TIMER = 5000
title= program
File=
WinWaitActive, ahk_class GHOST_WindowClass
WinGetTitle, WinTitle, program.exe
file := RegExReplace(title, ".*\[(.*)\]$", "$1")
if file=
{
    msgbox, CANNOT GET FILENAME FROM TITLE: "%title%"
    exitapp
}
TrayTip, EXE, % "Now watching for " file
Loop
{
    IfWinNotExist, %title% ahk_class GHOST_WindowClass
    {
        IfWinExist, ahk_exe blender.exe
            goto next
        TrayTip, EXE, % "Restarting " file
        Run, location file here %file%
        WinWaitActive, ahk_class GHOST_WindowClass
        Sleep, 6000
        Send, ^{f12}
    }
next:
    Sleep TIMER
}
+0::exitapp
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: run automatically during certain hours

05 May 2021, 09:21

It seems like this could be simplified. An example is below.

Code: Select all

app = notepad.exe
Loop {
 WinWaitClose, % wTitle := "ahk_exe " app
 Sleep, 60000
 If WinExist(wTitle)
  Continue
 Run, %app%
 WinWait, %wTitle%
}
SchmutzigeT
Posts: 3
Joined: 05 May 2021, 07:12

Re: run automatically during certain hours

06 May 2021, 09:21

Thx I'll give it a go.

Still need to find a way to run the program during specifiek hours.
I found the windows scheduler that can run a program at a certain time. It might be a solution to make a script that opens the program en keeps an eye out for crashes and schedule it for 08:00
Make another script that closes these programs and set in the schedule at 19:00 and close it afterwards.
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: run automatically during certain hours

06 May 2021, 09:34

Sure. The Windows Task Scheduler is efficient for starting a program at a specific time.
M4verick
Posts: 193
Joined: 03 Nov 2020, 12:00

Re: run automatically during certain hours

06 May 2021, 10:31

SchmutzigeT wrote:
06 May 2021, 09:21
Thx I'll give it a go.

Still need to find a way to run the program during specifiek hours.
Maybe this thread will help you?

https://www.autohotkey.com/boards/viewtopic.php?f=76&t=90054
SchmutzigeT
Posts: 3
Joined: 05 May 2021, 07:12

Re: run automatically during certain hours

11 May 2021, 09:18

mikeyww wrote:
05 May 2021, 09:21
It seems like this could be simplified. An example is below.

Code: Select all

app = notepad.exe
Loop {
 WinWaitClose, % wTitle := "ahk_exe " app
 Sleep, 60000
 If WinExist(wTitle)
  Continue
 Run, %app%
 WinWait, %wTitle%
}
Not sure what I'm doing wrong. It seems to either not restart the progam after it shuts down or it opens multiple versions of the program when it is still running.
Or get stuck at WinWait, %wTitle%
User avatar
mikeyww
Posts: 26945
Joined: 09 Sep 2014, 18:38

Re: run automatically during certain hours

11 May 2021, 10:55

Are you testing with Notepad?
How can you tell where it is stuck? You can add lines to determine that.
If you shorten the sleep to a few seconds, debugging may be easier.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: No registered users and 219 guests