Can't terminate scripts Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CaseyMoon
Posts: 5
Joined: 25 Mar 2024, 08:22

Can't terminate scripts

03 Apr 2024, 13:03

Code: Select all

Right::
    ToggleScripts()
return

ToggleScripts() {
    static toggle := false
    toggle := !toggle
    if (toggle) {
        ; Terminate (L) Scripts
        Run, % A_ComSpec " /c taskkill /F /IM ""Strike (L).ahk"" /T",, Hide
        Run, % A_ComSpec " /c taskkill /F /IM ""Supers (L).ahk"" /T",, Hide
        
        ; Run (R) Scripts
        Run, "Strike (R).ahk", , Min
        Run, "Supers (R).ahk", , Min
    } else {
        ; Terminate (R) Scripts
        Run, % A_ComSpec " /c taskkill /F /IM ""Strike (R).ahk"" /T",, Hide
        Run, % A_ComSpec " /c taskkill /F /IM ""Supers (R).ahk"" /T",, Hide
        
        ; Run (L) Scripts
        Run, "Strike (L).ahk", , Min
        Run, "Supers (L).ahk", , Min
    }
}
Hi there,

The above script doesn't work. I'm trying to launch two scripts, while terminating two other scripts, and vice versa, using Right as my toggle hotkey. Launching the scripts works, but terminating the scripts doesn't. I have tried other options like "Process, Close" but it doesn't let me terminate either. What could be the issue?
User avatar
V0RT3X
Posts: 245
Joined: 20 May 2023, 21:59
Contact:

Re: Can't terminate scripts

03 Apr 2024, 15:24

Try adding this to the top of your script...

Code: Select all

DetectHiddenWindows, On
CaseyMoon
Posts: 5
Joined: 25 Mar 2024, 08:22

Re: Can't terminate scripts

03 Apr 2024, 15:49

V0RT3X wrote:
03 Apr 2024, 15:24
Try adding this to the top of your script...

Code: Select all

DetectHiddenWindows, On
Thank you for your suggestion. Unfortunately, adding this to the top of my script didn't fix not being able to terminate my other scripts.
User avatar
mikeyww
Posts: 27282
Joined: 09 Sep 2014, 18:38

Re: Can't terminate scripts  Topic is solved

03 Apr 2024, 20:21

How to close a script

Code: Select all

; This script closes another script
#Requires AutoHotkey v1.1.33.11
script := A_ScriptDir "\test.ahk" ; Full path to the script to close

F2::
DetectHiddenWindows On
WinClose % script " ahk_class AutoHotkey"
MsgBox 64, Status, Done!
Return
Your uncompiled AHK script file does not run as an executable program per se. It is just a text file. It is interpreted by AutoHotkey.exe (or a variant), which does run as an executable program. AutoHotkey uses the script's path as the leading text of its case-sensitive window title.
CaseyMoon
Posts: 5
Joined: 25 Mar 2024, 08:22

Re: Can't terminate scripts

04 Apr 2024, 16:15

mikeyww wrote:
03 Apr 2024, 20:21
How to close a script

Code: Select all

; This script closes another script
#Requires AutoHotkey v1.1.33.11
script := A_ScriptDir "\test.ahk" ; Full path to the script to close

F2::
DetectHiddenWindows On
WinClose % script " ahk_class AutoHotkey"
MsgBox 64, Status, Done!
Return
Your uncompiled AHK script file does not run as an executable program per se. It is just a text file. It is interpreted by AutoHotkey.exe (or a variant), which does run as an executable program. AutoHotkey uses the script's path as the leading text of its case-sensitive window title.
Thank you! This helped me understand and fix the issue. I solved it by compiling the targeted scripts into .exe files.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 127 guests