WinClose works for all but *ONE* AHK Script?
Posted: 30 Jan 2021, 06:58
Hello all,
I have come across an issue that has me scratching my head…
I have a large main script, and inside it, I load many other, smaller scripts during the autoexecute section of my code:
Where:
(the Min2Tray script is by @Junyx - see here)
To exit or refresh my codes, I have created two hotkeys – Exit and Reload. In them, I close out of all the standalone scripts that have been started. However, the Min2TrayJunyx.ahk will only close in the exit hotkey, and not the reload.
Exit
Reload
In the above cases, the Exit (CloseCode:) hotkey will cause the Min2Tray to close, but the Reload (ReloadCode:) causes an error message to pop up saying that Min2Tray is already running when it tries to reload my script.
However, I also found this response by @mikeyww, and then finding a script by @just me to find the PID of the script and swapping the last line for:
It now closes Min2Tray! What's weirder is that I have a GUI with buttons that directly toggle the stand alone scripts on and off as needed. The button for Min2Tray is as follows:
This closes Min2Tray every time?!
My question is: is there anything that may be in the Min2Tray.ahk file that could stop the WinClose from working?
submeg
I have come across an issue that has me scratching my head…
I have a large main script, and inside it, I load many other, smaller scripts during the autoexecute section of my code:
Code: Select all
;Ensure that all the standalone items are run independently
run, %ParentPath%\AutoHotkeyU64.exe %AutoCorrectFullPath% ;Enables Microsoft Office Autocorrector across other programs.
run, %ParentPath%\AutoHotkeyU64.exe %DesktopFullPath% ;Create a button in the taskbar that allows you to Alt+Tab to desktop and drag files to it.
run, %ParentPath%\AutoHotkeyU64.exe %Min2TrayFullPath% ;Allow programs to be minimised to the system tray.
- ParentPath is determined during boot up and is dependent on the device I am working on (can show this if needed)
- The full path is as follows:
Code: Select all
Min2TrayFullPath = "%ParentPath%Lib\Min2TrayJunyx.ahk"
To exit or refresh my codes, I have created two hotkeys – Exit and Reload. In them, I close out of all the standalone scripts that have been started. However, the Min2TrayJunyx.ahk will only close in the exit hotkey, and not the reload.
Exit
Code: Select all
CloseCode:
PerformAction_ResetKeys()
SetTitleMatchMode, 2
msg := ""
msg := "Shortcuts closing, goodbye!"
ToolTip, %msg%
Sleep, 1500
SetTimer, RemoveToolTip, -1500
msg := ""
Run, %A_ScriptDir%
;https://autohotkey.com/board/topic/39319-how-do-you-close-another-ahk-script-solved/#entry246777
DetectHiddenWindows, On
WinClose, Lib\PushToShow.ahk ahk_class AutoHotkey
WinClose, Lib\TicTocTitle.ahk ahk_class AutoHotkey
WinClose, Lib\AutoCorrect.ahk ahk_class AutoHotkey
WinClose, Lib\MouseMark.ahk ahk_class AutoHotkey
WinClose, Lib\MouseGestureL.ahk ahk_class AutoHotkey
WinClose, Lib\AHKTaskLog.ahk ahk_class AutoHotkey
WinClose, Lib\White.ahk ahk_class AutoHotkey
WinClose, Lib\MouseMover.ahk ahk_class AutoHotkey
WinClose, Lib\White.ahk ahk_class AutoHotkey
WinClose, Lib\Desktop.ahk ahk_class AutoHotkey
WinClose, Lib\Min2TrayJunyx.ahk ahk_class AutoHotkey
ExitApp
Return
Code: Select all
ReloadCode:
msg := ""
msg := "Shortcuts reloading..."
ToolTip, %msg%
Sleep, 800
SetTimer, Settings_RemoveToolTip, -800
msg := ""
WinClose, Lib\PushToShow.ahk ahk_class AutoHotkey
WinClose, Lib\TicTocTitle.ahk ahk_class AutoHotkey
WinClose, Lib\AutoCorrect.ahk ahk_class AutoHotkey
WinClose, Lib\MouseMark.ahk ahk_class AutoHotkey
WinClose, Lib\MouseGestureL.ahk ahk_class AutoHotkey
WinClose, Lib\AHKTaskLog.ahk ahk_class AutoHotkey
WinClose, Lib\White.ahk ahk_class AutoHotkey
WinClose, Lib\MouseMover.ahk ahk_class AutoHotkey
WinClose, Lib\White.ahk ahk_class AutoHotkey
WinClose, Lib\Desktop.ahk ahk_class AutoHotkey
WinClose, Lib\Desktop.ahk ahk_class AutoHotkey
WinClose, Lib\Min2TrayJunyx.ahk ahk_class AutoHotkey
Reload
Return
However, I also found this response by @mikeyww, and then finding a script by @just me to find the PID of the script and swapping the last line for:
Code: Select all
Process, Close, %ScriptPIDIs% ;where ScriptPIDIs is the PID of Min2Tray
Code: Select all
Min2Tray:
;https://autohotkey.com/board/topic/39319-how-do-you-close-another-ahk-script-solved/#entry246777
SetTitleMatchMode, 2
DetectHiddenWindows, On
IfWinExist, Lib\Min2TrayJunyx.ahk ahk_class AutoHotkey
{
WinClose, Lib\Min2TrayJunyx.ahk ahk_class AutoHotkey ;stop Min2Tray
}
else
{
run, %ParentPath%\AutoHotkeyU64.exe %Min2TrayFullPath% ;Start Mouse Gestures.
}
Return
This closes Min2Tray every time?!
My question is: is there anything that may be in the Min2Tray.ahk file that could stop the WinClose from working?
submeg