WinClose works for all but *ONE* AHK Script? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

WinClose works for all but *ONE* AHK Script?

Post by submeg » 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:

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.
Where:
  • 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"
(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

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
Reload

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
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:

Code: Select all

Process, Close, %ScriptPIDIs%		;where ScriptPIDIs is the PID of Min2Tray
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:

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
Last edited by submeg on 30 Jan 2021, 15:18, edited 2 times in total.
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: WinClose works for all but *ONE* AHK Script?

Post by just me » 30 Jan 2021, 07:12

Your Reload section does not contain DetectHiddenWindows, On .

User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: WinClose works for all but *ONE* AHK Script?

Post by submeg » 30 Jan 2021, 07:15

just me wrote:
30 Jan 2021, 07:12
Your Reload section does not contain DetectHiddenWindows, On .
Hey @just me, quite right! I updated it, but still shows up the error during boot:

Error: Min2Tray is already running!

Code: Select all

ReloadCode:

DetectHiddenWindows, On 

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

;Process, Close, %ScriptPIDIs%

Reload

Return 
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

just me
Posts: 9424
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: WinClose works for all but *ONE* AHK Script?

Post by just me » 31 Jan 2021, 07:56

Seems that MinToTray runs one 'master' instance and several 'client' instances. So you might need to close more than one instance.

User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

Re: WinClose works for all but *ONE* AHK Script?  Topic is solved

Post by submeg » 22 Jun 2021, 04:30

The solution:

If you can't close the AHK script using WinClose:

Code: Select all

WinClose, Lib\AutoCorrect.ahk ahk_class AutoHotkey
you can close it with its processID -

Code: Select all

Process, Close, %Min2TrayPIDIs%
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:

Post Reply

Return to “Ask for Help (v1)”