Trying to get some coding written by GPT - and not doing as well as hoped.
This script opens Sumatra PDF reader and will refocus on it whenever the script is called, say via a binding. Some programs refuse to refocus when their paths are substituted - Cantabile being one such program. The script will do a one time launch but will not regain focus if the script is run again. Iβm mystified as to why this fails. The Cherry GX-80 also fails to refocus.
Any ideas?
Cheers!
AutoIt script:
; Check if Sumatra is running
If Not WinExists(β[CLASS:SumatraMainWindow]β) Then
; Launch Sumatra if itβs not already open
Run(βC:\Program Files\SumatraPDF\SumatraPDF.exeβ)
WinWait(β[CLASS:SumatraMainWindow]β)
EndIf
A Cantabile script using additional methods to force focus as recommended by GPT - only provides a one time launch.
; Check if Cantabile is running
$hWnd = WinGetHandle(β[CLASS:CantabileMainWindow]β, β[EXE:Cantabile.exe]β)If $hWnd = 0 Then
; Launch Cantabile if itβs not already open
Run(βC:\Program Files\Topten Software\Cantabile 4.0\Cantabile.exeβ)
WinWait(β[CLASS:CantabileMainWindow]β)
Else
; Activate Cantabile window if itβs already open
WinActivate($hWnd)
WinWaitActive($hWnd)
EndIf; Set focus on Cantabile main window control
ControlFocus($hWnd, ββ, β[CLASS:CantabileMainWindow]β); Wait for the control to have focus
ControlFocus($hWnd, ββ, β[CLASS:CantabileMainWindow]β)