Search code examples
automationscriptingkeyboard-shortcutsautohotkeyhotkeys

Do I have to put `SetTitleMatchMode` on top of the script?


Sample script:

#NoEnv
#Warn
#SingleInstance Force

#IfWinActive Foo ahk_exe foo.exe
  !A::Send Foo

SetTitleMatchMode Regex

#IfWinActive Bar$ ahk_exe bar.exe
  !A::Send Bar

When running it, the interpreter throws:

enter image description here

I want to apply SetTitleMatchMode Regex only to bar.exe, is it achievable without putting it on top of the script?


Solution

  • Quote from SetTitleMatchMode Remarks:

    Every newly launched thread (such as a hotkey, custom menu item, or timed subroutine) starts fresh with the default setting for this command. That default may be changed by using this command in the auto-execute section (top part of the script).

    And quote from The Top of the Script (the Auto-execute Section):

    After the script has been loaded, it begins executing at the top line, continuing until a Return, Exit, hotkey/hotstring label, or the physical end of the script is encountered (whichever comes first). This top portion of the script is referred to as the auto-execute section.