I found a way to accomplish this without having to modify ignition or use outside scripting. The code below checks to see if a designated app is open, and if so, it dynamically creates a temporary script in the user's cache file that does the work of swapping windows. Once the file is written to cache, the code below doesn't rewrite it again, but rather, just executes the file directly each time the script is called.
Here is the code with "chrome" designated as the target app:
import os
import getpass
from java.lang import Runtime
from java.io import InputStreamReader
from java.io import BufferedReader
def isAppRunning(taskName):
processList= BufferedReader(InputStreamReader(Runtime.getRuntime().exec("tasklist.exe").getInputStream()))
testLines = ""
while testLines != None:
if taskName in testLines:
processList.close()
return True
testLines = processList.readLine()
processList.close()
return False
taskName = "chrome"
if isAppRunning(taskName):
username = getpass.getuser()
path = "C:/Users/" + username + "/.ignition/cache/tempFile.bat"
if not os.path.exists(path):
scriptLines = [
"@echo WScript.CreateObject(\"WScript.Shell\").AppActivate(WScript.Arguments.Item(0))>%tmp%\switch.vbs",
"%tmp%\switch.vbs \""+taskName+"\"",
"exit"]
with open(path, "w") as tf:
for line in scriptLines:
tf.write(line + "\n")
system.util.execute([path])
Here is the result:
Initially, I did this as proof of concept to see if this approach was even work pursuing, and I had no intentions of actually using a batch file in the end product because I didn't like the idea of an annoying black popup appearing and disappearing. However, to my surprise, and as you can see in the video, the popup never appears [at least not on my system].
Obviously, there is nothing in this code that will specify which instance of a target app to give focus to, so if a user has multiple instances of a target app open, your guess is as good as mine as to which one will gain focus.
Edit: Corrected a flaw in the while loop design that was causing half the tasklist lines to be consumed without being checked and that was creating an occasional None type object error that required exception handling. The no longer needed exception handling has been removed.