may try this at the beginning.
<code>
#SingleInstance force
#Persistent ; Keeps a script permanently running (that is, until the user closes it or ExitApp is encountered).
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.