I would like to ask the community for help on a seemingly basic command that somehow doesn't work on one specific device.
It is a script that replaces the caps lock key with the following:
- * check for an existing instance of chrome.exe
* if this exists, switch to Chrome; if currently on a new tab, close it, else open a new tab and go to address bar
* if there is no existing instance of chrome.exe, run it
After progressively trimming down the script to identify the problem, I am left with the following bare-bone script:
Code: Select all
Capslock::
SetTitleMatchMode, 2
If WinExist ("ahk_exe chrome.exe")
{
WinActivate, ahk_exe chrome.exe
Send ^t
}
else
{
Run "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
WinActivate, ahk_exe chrome.exe
Send ^l
Send ^t
}
return
+Capslock::Capslock
The desired result of this trimmed down script is:
Check if Chrome is running. If so, switch to it and open a new tab; if not, run Chrome, switch to it, go to navigation bar, then open a new tab.
Instead, I observe the following behaviour:
When Chrome is running, the script runs successfully (i.e. switches to Chrome and opens a new tab).
When Chrome is NOT running, however, the script behaves unpredictably. A few hours ago, it sent ^l and ^t without running Chrome (which results in explorer going to the navigation bar with ^l then playing an error sound); but now, it appears to just sit there and do absolutely nothing when Chrome isn't already running.
Could someone shed some light on why this might be happening, and how I can change the code to make it more stable?
Thanks!