I just want to have a script that can reload my main script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
supplementfacts
Posts: 41
Joined: 15 Jul 2018, 16:29

I just want to have a script that can reload my main script

Post by supplementfacts » 08 Feb 2023, 21:51

My main script is AutoHotkey.ahk. Sometimes it runs into trouble and Pauses itself. Then I have to right-click on the red taskbar icon and select 'Reload this Script'. This always works fine. The script is back to square one, it just hangs out waiting for me to give input, and (importantly) it's not in the middle of the procedure that led it into trouble. The only problem is that it's annoying to have to right-click every time the script runs into trouble. I'd prefer to be able to type something like 'sss' and have that do the very same thing that right-clicking and selecting 'Reload this Script' does.

So here's what I have in a second script:

Code: Select all

:?*:sss::
Sleep, 300
DetectHiddenWindows, On 
WinClose, %A_ScriptDir%\AutoHotkey.ahk
Sleep, 500
Run, %A_ScriptDir%\AutoHotkey.ahk  " /restart"       ; I've also tried this line without the quotation marks, and with /force added
return
But this doesn't work. Admittedly, it successfully closes the main script and then runs it again. But it doesn't reload the main script from square one. Instead, the main script picks up where it left off, and continues with the procedure that led it into trouble. This is exactly what I don't want to happen.

Does anyone know an easy way to have a second script that accomplishes the same thing that is accomplished by right-clicking my main script's red paused taskbar icon and selecting 'Reload this Script'? Thanks!

User avatar
boiler
Posts: 16923
Joined: 21 Dec 2014, 02:44

Re: I just want to have a script that can reload my main script

Post by boiler » 08 Feb 2023, 22:21

Why not just have your main script reload your main script? If you add the following hotstring, it should work even when it's paused.

Code: Select all

:?*X:sss::Reload

User avatar
lmstearn
Posts: 694
Joined: 11 Aug 2016, 02:32
Contact:

Re: I just want to have a script that can reload my main script

Post by lmstearn » 08 Feb 2023, 22:32

Code: Select all

Run, "%A_ScriptDir%\AutoHotkey.ahk"  /restart
Another option is to setup a hotkey with Reload, and send the hotkey to the script. (ninja'd)
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

User avatar
Datapoint
Posts: 295
Joined: 18 Mar 2018, 17:06

Re: I just want to have a script that can reload my main script

Post by Datapoint » 08 Feb 2023, 23:36

Maybe the last example at the bottom of the page here: https://www.autohotkey.com/docs/v1/misc/SendMessage.htm

supplementfacts
Posts: 41
Joined: 15 Jul 2018, 16:29

Re: I just want to have a script that can reload my main script

Post by supplementfacts » 09 Feb 2023, 18:27

boiler wrote:
08 Feb 2023, 22:21
Why not just have your main script reload your main script? If you add the following hotstring, it should work even when it's paused.

Code: Select all

:?*X:sss::Reload
I'd like to do other things with the second script while the main script is reloading. In any case, do you know how to have the second script reload the main script?

supplementfacts
Posts: 41
Joined: 15 Jul 2018, 16:29

Re: I just want to have a script that can reload my main script

Post by supplementfacts » 09 Feb 2023, 18:29

lmstearn wrote:
08 Feb 2023, 22:32

Code: Select all

Run, "%A_ScriptDir%\AutoHotkey.ahk"  /restart
Another option is to setup a hotkey with Reload, and send the hotkey to the script. (ninja'd)
Unless I'm mistaken, the code you've provided is exactly what the comment in my code says I've already tried. It 'reloads' the main script in the middle of the procedure that led to trouble.

Also, I'm not sure what you mean by setting up a hotkey with Reload, what it means to send a hotkey to a script, and which script you mean it would be sent to. Could you explain further? Thanks!

supplementfacts
Posts: 41
Joined: 15 Jul 2018, 16:29

Re: I just want to have a script that can reload my main script

Post by supplementfacts » 09 Feb 2023, 18:30

Datapoint wrote:
08 Feb 2023, 23:36
Maybe the last example at the bottom of the page here: https://www.autohotkey.com/docs/v1/misc/SendMessage.htm
Unless I'm mistaken, that reloads every script. That means the second script would also be reloaded. I merely want to reload the main script.

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: I just want to have a script that can reload my main script

Post by swagfag » 09 Feb 2023, 19:04

this boggles the mind. why did u write a script that pauses itself when it runs into an error in the first place? remove the pause, then u dont need additional scripts and hotkeys

User avatar
DuckingQuack
Posts: 219
Joined: 20 Jan 2023, 18:20

Re: I just want to have a script that can reload my main script

Post by DuckingQuack » 09 Feb 2023, 19:34

I'd like to second Swag on that, because it seems better to debug it rather than work around it being buggy. However, if the hang-up is intentional, why not throw in a hotkey with gosub to take yourself to a place in the script that will function?
Best of Luck,
The Duck

User avatar
boiler
Posts: 16923
Joined: 21 Dec 2014, 02:44

Re: I just want to have a script that can reload my main script

Post by boiler » 09 Feb 2023, 19:50

supplementfacts wrote:
09 Feb 2023, 18:27
boiler wrote:
08 Feb 2023, 22:21
Why not just have your main script reload your main script? If you add the following hotstring, it should work even when it's paused.

Code: Select all

:?*X:sss::Reload
I'd like to do other things with the second script while the main script is reloading. In any case, do you know how to have the second script reload the main script?
And how exactly does the main script reloading itself prevent you from doing things with the second script while the main script is reloading?

supplementfacts
Posts: 41
Joined: 15 Jul 2018, 16:29

Re: I just want to have a script that can reload my main script

Post by supplementfacts » 09 Feb 2023, 19:55

swagfag wrote:
09 Feb 2023, 19:04
this boggles the mind. why did u write a script that pauses itself when it runs into an error in the first place? remove the pause, then u dont need additional scripts and hotkeys
The script is working with a website that is unpredictable, so this is a lot easier than trying to debug in response to chaos.

supplementfacts
Posts: 41
Joined: 15 Jul 2018, 16:29

Re: I just want to have a script that can reload my main script

Post by supplementfacts » 09 Feb 2023, 19:57

boiler wrote:
09 Feb 2023, 19:50
supplementfacts wrote:
09 Feb 2023, 18:27
boiler wrote:
08 Feb 2023, 22:21
Why not just have your main script reload your main script? If you add the following hotstring, it should work even when it's paused.

Code: Select all

:?*X:sss::Reload
I'd like to do other things with the second script while the main script is reloading. In any case, do you know how to have the second script reload the main script?
And how exactly does the main script reloading itself prevent you from doing things with the second script while the main script is reloading?
Because then the command would be based on the main script, not the second script. So I'd have to run a command to reload the main script, and then run a second command off the second script. I'd prefer to just run a command off the second script that reloads the main script and does additional things.

supplementfacts
Posts: 41
Joined: 15 Jul 2018, 16:29

Re: I just want to have a script that can reload my main script

Post by supplementfacts » 09 Feb 2023, 19:58

DuckingQuack wrote:
09 Feb 2023, 19:34
I'd like to second Swag on that, because it seems better to debug it rather than work around it being buggy. However, if the hang-up is intentional, why not throw in a hotkey with gosub to take yourself to a place in the script that will function?
The hang-up isn't intentional. It's due to a website that behaves erratically. Do you know how to have the second script reload the main script?

User avatar
lmstearn
Posts: 694
Joined: 11 Aug 2016, 02:32
Contact:

Re: I just want to have a script that can reload my main script

Post by lmstearn » 09 Feb 2023, 21:08

supplementfacts wrote:
09 Feb 2023, 18:29
lmstearn wrote:
08 Feb 2023, 22:32

Code: Select all

Run, "%A_ScriptDir%\AutoHotkey.ahk"  /restart
Another option is to setup a hotkey with Reload, and send the hotkey to the script. (ninja'd)
Unless I'm mistaken, the code you've provided is exactly what the comment in my code says I've already tried. It 'reloads' the main script in the middle of the procedure that led to trouble.
Sorry should have emphasised the quotes:

Run, "%A_ScriptDir%\AutoHotkey.ahk" /restart
supplementfacts wrote:
09 Feb 2023, 18:29
Also, I'm not sure what you mean by setting up a hotkey with Reload, what it means to send a hotkey to a script, and which script you mean it would be sent to. Could you explain further? Thanks!
Setup a hotkey in the problem script like

Code: Select all

^R::Reload
Then in the calling script use

Code: Select all

:?*:sss::
...
if WinActive("AutoHotkey.ahk")
Send ^R
Would something like this work for you- haven't tested it here yet.
:arrow: itros "ylbbub eht tuO kaerB" a ni kcuts m'I pleH

User avatar
Datapoint
Posts: 295
Joined: 18 Mar 2018, 17:06

Re: I just want to have a script that can reload my main script

Post by Datapoint » 09 Feb 2023, 21:35

supplementfacts wrote:
09 Feb 2023, 18:30
Datapoint wrote:
08 Feb 2023, 23:36
Maybe the last example at the bottom of the page here: https://www.autohotkey.com/docs/v1/misc/SendMessage.htm
Unless I'm mistaken, that reloads every script. That means the second script would also be reloaded. I merely want to reload the main script.
I guess I didn't explain that you would need to modify it to only find your one script.

This reloads test.ahk

Code: Select all

:?*:sss::
ReloadScript()
{
	DetectHiddenWindows, On
	SetTitleMatchMode, 2
	PostMessage, 0x0111, 65303,,, test.ahk ahk_class AutoHotkey
	return
}
*edited

Post Reply

Return to “Ask for Help (v1)”